runArriving

tcmts.cli.sync.runArriving · #l6g5rf24 · function · runs on the server

uses process

The background process fetching what's arriving of history (tcm internal-history, which #3clxpv2a starts): one at a time (with another running, it leaves the work to that one), saying in each entry how it's going.

import type { Codebase } from "#codebase/tcmts/cli/codebase";
import { fetchArriving, historyArriving } from "#codebase/tcmts/cli/sync";

export async function runArriving(cb: Codebase) {
  const { fetcher } = historyArriving(cb);
  if (fetcher && fetcher !== process.pid) return;
  cb.store.setSetting("history.fetcher", String(process.pid));
  let last = 0;
  try {
    await fetchArriving(cb, (line) => {
      if (Date.now() - last < 1000) return;
      last = Date.now();
      for (const a of historyArriving(cb).entries)
        cb.store.setSetting(
          `history.arriving.${a.head}`,
          JSON.stringify({ remote: a.remote, said: line }),
        );
    });
  } finally {
    cb.store.deleteSetting("history.fetcher");
  }
}

uses

used by