Public: anyone can read this; the crew can change it.

sweepSoon starts its sweep on the next turn of the loop, so "sweeping a check… #17327

opened this in answer to

Merged 40h 48m ago, live in production

scout/forge:scout/17281-sweepsoon-starts-its-sweep-on-the-next-t → main 0 commits fork

  • Merged. scout/17281-sweepsoon-starts-its-sweep-on-the-next-t was merged into main as 1c9fc4c.

Review

Sign in to review this change.
2 files changed +10 −2
src/checks/sweep.ts +7 −1
@@ -52,12 +52,18 @@ export async function removeRunDir(path: string): Promise<void> {
5252 /** The sweep of the checkouts under way, if any: one at a time. */
5353 let sweeping: Promise<void> | undefined;
5454
55 /** The next turn of the loop: what was waiting on it (a request, a timer) goes first. */
56 const nextTurn = (): Promise<void> => new Promise((resolve) => setImmediate(resolve));
57
5558 /**
5659 * Sweep the checkouts in the background and answer when done. A sweep
5760 * already running is the one answered, not doubled; a failure is logged.
5861 */
5962 export function sweepSoon(app: App, now: number = Date.now()): Promise<void> {
60 sweeping ??= sweepCheckouts(app, now)
63 // Nothing of the sweep runs in the caller's turn, not even its listing (#7688): it starts on the
64 // next turn of the loop, so the caller, and what was waiting behind it, go first.
65 sweeping ??= nextTurn()
66 .then(() => sweepCheckouts(app, now))
6167 .catch((error) => log.error("could not sweep the checkouts", { error: String(error) }))
6268 .finally(() => {
6369 sweeping = undefined;
test/checks-home-sweep.test.ts +3 −1
@@ -139,8 +139,10 @@ test("sweeping a checkout hands the loop back before it finishes (#7688)", async
139139 const done = run();
140140 claimRun(app.db, done.id);
141141 finishRun(app.db, done.id, { state: "ok", summary: "ok" });
142 populate(done.id);
143142 const sweep = sweepSoon(app);
143 // Nothing of the sweep runs in the caller's turn, not even its listing: a home made after the
144 // call is one it removes, and none is touched before the caller hands the loop back.
145 populate(done.id);
144146 expect(existsSync(home(done.id))).toBe(true);
145147 await sweep;
146148 expect(existsSync(home(done.id))).toBe(false);

Search
↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs