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
Merged 40h 48m ago, live in production
scout/forge:scout/17281-sweepsoon-starts-its-sweep-on-the-next-t → main 0 commits fork
2 files
changed +10
−2
src/checks/sweep.ts +7 −1
| @@ -52,12 +52,18 @@ export async function removeRunDir(path: string): Promise<void> { | ||
| 52 | 52 | /** The sweep of the checkouts under way, if any: one at a time. */ |
| 53 | 53 | let sweeping: Promise<void> | undefined; |
| 54 | 54 | |
| 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 | ||
| 55 | 58 | /** |
| 56 | 59 | * Sweep the checkouts in the background and answer when done. A sweep |
| 57 | 60 | * already running is the one answered, not doubled; a failure is logged. |
| 58 | 61 | */ |
| 59 | 62 | 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)) | |
| 61 | 67 | .catch((error) => log.error("could not sweep the checkouts", { error: String(error) })) |
| 62 | 68 | .finally(() => { |
| 63 | 69 | 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 | ||
| 139 | 139 | const done = run(); |
| 140 | 140 | claimRun(app.db, done.id); |
| 141 | 141 | finishRun(app.db, done.id, { state: "ok", summary: "ok" }); |
| 142 | populate(done.id); | |
| 143 | 142 | 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); | |
| 144 | 146 | expect(existsSync(home(done.id))).toBe(true); |
| 145 | 147 | await sweep; |
| 146 | 148 | expect(existsSync(home(done.id))).toBe(false); |
new above
offline