diff --git a/frontend/src/lib/components/scripts/PerpetualRunsDeployModal.svelte b/frontend/src/lib/components/scripts/PerpetualRunsDeployModal.svelte index 1250075741..8a3137b5e9 100644 --- a/frontend/src/lib/components/scripts/PerpetualRunsDeployModal.svelte +++ b/frontend/src/lib/components/scripts/PerpetualRunsDeployModal.svelte @@ -16,7 +16,6 @@ const runsText = $derived.by(() => { if (!runs) return '' - if (runs.truncated) return `At least ${runs.count} runs of this script are` return runs.count === 1 ? '1 run of this script is' : `${runs.count} runs of this script are` }) diff --git a/frontend/src/lib/components/scripts/perpetualRuns.ts b/frontend/src/lib/components/scripts/perpetualRuns.ts index a2c6880f51..d30e5b443a 100644 --- a/frontend/src/lib/components/scripts/perpetualRuns.ts +++ b/frontend/src/lib/components/scripts/perpetualRuns.ts @@ -1,27 +1,37 @@ -import { JobService, ScriptService } from '$lib/gen' +import { JobService, ScriptService, type QueuedJob } from '$lib/gen' import { computeDiff } from '$lib/components/schema/schemaUtils.svelte' -const RUNS_PAGE_SIZE = 100 +const QUEUE_PAGE_SIZE = 1000 export type PerpetualRunsAtPath = { count: number - /** More runs than one page holds are queued at the path, so `count` is a lower bound. */ - truncated: boolean /** Arguments the deployed schema removes, retypes or newly requires, compared with the runs' versions. */ mismatchedArgs: string[] } +// Every page: the deploy switches every perpetual run at the path, so one past the first page +// still needs the prompt and its version's arguments compared. +async function listQueuedAtPath(workspace: string, path: string): Promise { + const jobs = new Map() + for (let page = 1; ; page++) { + const batch = await JobService.listQueue({ + workspace, + scriptPathExact: path, + jobKinds: 'script', + perPage: QUEUE_PAGE_SIZE, + page + }) + for (const job of batch) jobs.set(job.id, job) + if (batch.length < QUEUE_PAGE_SIZE) return [...jobs.values()] + } +} + export async function loadPerpetualRunsAtPath( workspace: string, path: string, schema: { [key: string]: any } | undefined ): Promise { - const queued = await JobService.listQueue({ - workspace, - scriptPathExact: path, - jobKinds: 'script', - perPage: RUNS_PAGE_SIZE - }) + const queued = await listQueuedAtPath(workspace, path) // Only what the backend restarts: never a flow step, and only a run of a perpetual version. const candidates = queued.filter((job) => !job.is_flow_step && job.script_hash) const hashes = [...new Set(candidates.map((job) => job.script_hash!))] @@ -56,7 +66,6 @@ export async function loadPerpetualRunsAtPath( return { count: runs.length, - truncated: queued.length === RUNS_PAGE_SIZE, mismatchedArgs: [...mismatchedArgs] } }