Public: anyone can read this; the crew can change it.
Full suite red: test/flow-clock.test.ts #11989
Check · Review · Land · Live done — Landed and live in production.
mason/forge:mason/11987-full-suite-red-test-flow-clock-test-ts → main 1 commit fork 1 thread · 1 unresolved
1 file
changed +5
−6
src/flow/pipeline.ts +5 −6
| @@ -150,13 +150,12 @@ export function waitingOffThread(db: Database, sql: string, ...args: string[]): | ||
| 150 | 150 | * first count (nothing to serve yet), a database with no file, or a worker |
| 151 | 151 | * that has failed for long is counted on the thread. |
| 152 | 152 | */ |
| 153 | function waitingTally(db: Database, sql: string, ...args: string[]): Tally { | |
| 153 | function waitingTally(db: Database, now: number, sql: string, ...args: string[]): Tally { | |
| 154 | 154 | if (WAITING_REUSE_MS === 0) return countWaiting(db, sql, ...args); |
| 155 | 155 | let kept = waitingKept.get(db); |
| 156 | 156 | if (kept === undefined) waitingKept.set(db, (kept = new Map())); |
| 157 | 157 | // A `since` cutoff argument moves every call; the stage, not the instant, is the key. |
| 158 | 158 | const hit = kept.get(sql); |
| 159 | const now = Date.now(); | |
| 160 | 159 | if (hit !== undefined && now - hit.at < WAITING_REUSE_MS) return hit.tally; |
| 161 | 160 | const filed = db.filename !== "" && db.filename !== ":memory:"; |
| 162 | 161 | if (hit !== undefined && filed && now - hit.at < WAITING_REUSE_MS * WAITING_STALE_PERIODS) { |
| @@ -164,7 +163,7 @@ function waitingTally(db: Database, sql: string, ...args: string[]): Tally { | ||
| 164 | 163 | hit.asking = true; |
| 165 | 164 | waitingOffThread(db, sql, ...args).then( |
| 166 | 165 | (tally) => { |
| 167 | kept.set(sql, { at: Date.now(), tally, asking: false }); | |
| 166 | kept.set(sql, { at: now, tally, asking: false }); | |
| 168 | 167 | }, |
| 169 | 168 | () => { |
| 170 | 169 | hit.asking = false; |
| @@ -246,7 +245,7 @@ function tally(db: Database, key: PipelineKey, now: Date): Tally { | ||
| 246 | 245 | const iso = now.toISOString(); |
| 247 | 246 | switch (key) { |
| 248 | 247 | case "ready": |
| 249 | return waitingTally(db, READY); | |
| 248 | return waitingTally(db, now.getTime(), READY); | |
| 250 | 249 | case "building": |
| 251 | 250 | return runTally(db, "agent", "reason != 'review'", iso); |
| 252 | 251 | case "check-queue": |
| @@ -256,9 +255,9 @@ function tally(db: Database, key: PipelineKey, now: Date): Tally { | ||
| 256 | 255 | case "review": |
| 257 | 256 | return runTally(db, "agent", "reason = 'review'", iso); |
| 258 | 257 | case "approved": |
| 259 | return waitingTally(db, APPROVED); | |
| 258 | return waitingTally(db, now.getTime(), APPROVED); | |
| 260 | 259 | case "landed": |
| 261 | return waitingTally(db, LANDED, new Date(now.getTime() - 7 * DAY_MS).toISOString()); | |
| 260 | return waitingTally(db, now.getTime(), LANDED, new Date(now.getTime() - 7 * DAY_MS).toISOString()); | |
| 262 | 261 | case "live": |
| 263 | 262 | return liveTally(db, new Date(now.getTime() - DAY_MS).toISOString()); |
| 264 | 263 | } |
new above
offline
Stamping with the read-start instant is acceptable and was disclosed, but add a test that pins it. Consider also not overwriting a kept entry whose
atis newer thannow.