Pace engine reads under the proxy's rate limit

The proxy allows 10 requests a second per address and answers the rest
503. Limiting how many reads run at once still sent 40-50 a second, since
each answers in about 100 ms. Reads now share one pace of 8 a second,
actions skip the queue, and a 503 pauses every read for 2 seconds.
Results and Schedule share each schedule's production status, and an
archived schedule is read once until an action.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Iqbal
2026-10-30 10:06:40 +07:00
parent 138be5ac96
commit 977a8fafc4
6 changed files with 121 additions and 7 deletions

View File

@@ -350,7 +350,19 @@ export function planProgress(plan: ContentPlan) {
}
}
export const productionStatus = (id: number) => request<ProductionStatus>(`${AGENTS}/${id}/content`)
// The Schedule page (one query per row) and Results (one read per schedule) both poll this; a read
// from the last half minute, or one still on its way, answers both. forgetReads drops them after an action.
const PRODUCTION_FRESH = 30_000
const productionReads = new Map<number, { at: number; read: Promise<ProductionStatus> }>()
export function productionStatus(id: number): Promise<ProductionStatus> {
const kept = productionReads.get(id)
if (kept && Date.now() - kept.at < PRODUCTION_FRESH) return kept.read
const read = request<ProductionStatus>(`${AGENTS}/${id}/content`)
productionReads.set(id, { at: Date.now(), read })
read.catch(() => { if (productionReads.get(id)?.read === read) productionReads.delete(id) })
return read
}
export const forgetProductionReads = () => productionReads.clear()
// Produce now = the same plan the 09:00 tick would create, just earlier. The engine's tick then
// approves and starts it within a minute because Express schedules run in automatic mode.