Follow a running production every few seconds

A started production kept showing "AI picks new topics" for a minute
or more: each schedule's status was read once a minute, and the refresh
right after starting got the read kept from before the start. That read
is now dropped when a production starts, and while the latest production
is under way its status is read every five seconds.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Iqbal
2026-10-30 13:50:05 +07:00
parent 7a7f67d3e2
commit 677937eb98
2 changed files with 20 additions and 11 deletions

View File

@@ -397,9 +397,9 @@ export function planProgress(plan: ContentPlan) {
// 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> {
export function productionStatus(id: number, maxAge = PRODUCTION_FRESH): Promise<ProductionStatus> {
const kept = productionReads.get(id)
if (kept && Date.now() - kept.at < PRODUCTION_FRESH) return kept.read
if (kept && Date.now() - kept.at < maxAge) 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) })