historyArriving

tcmts.cli.sync.historyArriving · #72627d3v · function · runs on the server

uses process

The pulled heads whose history is still arriving (#2iulzpj4), each a setting of its own (history.arriving.<head>), and the process fetching it, if one is running (#vfh4t6l3).

import type { Codebase } from "#codebase/tcmts/cli/codebase";
import type { Arriving } from "#codebase/tcmts/cli/sync";

export function historyArriving(cb: Codebase): { entries: Arriving[]; fetcher?: number } {
  const entries = cb.store.settings("history.arriving.").map(([k, v]) => ({
    head: k.slice("history.arriving.".length),
    ...(JSON.parse(v) as { remote: string; said?: string }),
  }));
  const pid = Number(cb.store.getSetting("history.fetcher"));
  let alive = false;
  if (pid > 0)
    try {
      process.kill(pid, 0);
      alive = true;
    } catch (e) {
      alive = (e as NodeJS.ErrnoException).code === "EPERM";
    }
  return { entries, fetcher: alive ? pid : undefined };
}

uses

used by