Read only the schedules whose results changed, using the engine's agent status

Results polled one drafts endpoint per schedule every minute, archived ones
included, so the Network tab filled with video-drafts reads. Each poll now
reads GET /agents/status once (with If-None-Match, mostly a 304) and reads a
schedule's drafts again only when its status changed, while a production plan
is at work, or after 30 minutes so signed video URLs stay valid. Without the
status read, every schedule is read as before. The poll is now every 30s.

Also documents how Express uses the engine API in docs/engine-api.md.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Iqbal
2026-11-03 12:34:08 +07:00
parent 46730279cb
commit eb194df8e0
5 changed files with 262 additions and 24 deletions

View File

@@ -1,5 +1,5 @@
import { describe, expect, it } from 'vitest'
import { limiter, pacer } from './client'
import { afterEach, describe, expect, it, vi } from 'vitest'
import { limiter, pacer, request } from './client'
describe('limiter', () => {
it('runs at most n calls at once, all of them, failures included', async () => {
@@ -37,3 +37,21 @@ describe('pacer', () => {
expect(Date.now() - t0).toBeGreaterThanOrEqual(45)
})
})
describe('request with revalidate', () => {
afterEach(() => vi.unstubAllGlobals())
it('sends the last ETag back and answers a 304 with the last body', async () => {
const sent: (string | null)[] = []
vi.stubGlobal('fetch', vi.fn(async (_url: string, init: RequestInit) => {
const tag = new Headers(init.headers).get('If-None-Match')
sent.push(tag)
return tag
? new Response(null, { status: 304, headers: { ETag: 'W/"1"' } })
: new Response(JSON.stringify({ agents: [1] }), { status: 200, headers: { ETag: 'W/"1"' } })
}))
expect(await request('/etag-test', { revalidate: true })).toEqual({ agents: [1] })
expect(await request('/etag-test', { revalidate: true })).toEqual({ agents: [1] })
expect(sent).toEqual([null, 'W/"1"'])
})
})