diff --git a/frontend/src/lib/components/PersistentScriptDrawer.svelte b/frontend/src/lib/components/PersistentScriptDrawer.svelte index 47e1bced08..08afd16ecc 100644 --- a/frontend/src/lib/components/PersistentScriptDrawer.svelte +++ b/frontend/src/lib/components/PersistentScriptDrawer.svelte @@ -6,13 +6,14 @@ import { workspaceStore } from '$lib/stores' import { displayDate, sleep, sendUserToast } from '$lib/utils' import TableCustom from './TableCustom.svelte' - import { Hourglass, Loader2, Play } from 'lucide-svelte' + import { Hourglass, Loader2, Play, RefreshCw } from 'lucide-svelte' let dispatch = createEventDispatcher() let drawer: Drawer let script: Script let loadQueuedJobs = true + let queuedJobsLoading = false let queuedJobs: { status: 'running' | 'queued' jobId: string @@ -24,30 +25,44 @@ async function continuouslyLoadQueuedJobs() { while (loadQueuedJobs) { - let qjs = await JobService.listQueue({ - workspace: $workspaceStore ?? '', - orderDesc: false, - scriptPathExact: script.path - }) - let loadingQueuedJobs: { - status: 'running' | 'queued' - jobId: string - scheduledFor: string - scriptHash: string - }[] = [] - for (const qj of qjs) { - loadingQueuedJobs.push({ - status: qj.started_at ? 'running' : 'queued', - jobId: qj.id, - scriptHash: qj.script_hash ?? '', - scheduledFor: displayDate(qj.scheduled_for, true) - }) - } - queuedJobs = loadingQueuedJobs + loadQueuedJobsOnce() await sleep(3 * 1000) } } + async function loadQueuedJobsOnce() { + if (queuedJobsLoading) { + return + } + const timeStart = new Date().getTime() + queuedJobsLoading = true + let qjs = await JobService.listQueue({ + workspace: $workspaceStore ?? '', + orderDesc: false, + scriptPathExact: script.path + }) + let loadingQueuedJobs: { + status: 'running' | 'queued' + jobId: string + scheduledFor: string + scriptHash: string + }[] = [] + for (const qj of qjs) { + loadingQueuedJobs.push({ + status: qj.started_at ? 'running' : 'queued', + jobId: qj.id, + scriptHash: qj.script_hash ?? '', + scheduledFor: displayDate(qj.scheduled_for, true) + }) + } + queuedJobs = loadingQueuedJobs + const endStart = new Date().getTime() + // toggle queuedJobsLoading to false in 1 secs to let some time for the animation to play + setTimeout(() => { + queuedJobsLoading = false + }, 1000 - (endStart - timeStart)) + } + async function scaleToZero() { cancellingInProgress = true await JobService.cancelPersistentQueuedJobs({ @@ -66,7 +81,6 @@ console.log('Unable to open persistent script drawer without a proper script definition') return } - console.log('opening drawer') script = persistentScript! loadQueuedJobs = true continuouslyLoadQueuedJobs() @@ -75,7 +89,6 @@ async function exit() { loadQueuedJobs = false - console.log('closing drawer') drawer.closeDrawer?.() } @@ -94,9 +107,20 @@ on:close={exit} tooltip="Manage runs of persistent scripts. Scaling a persistent script to zero will cancel all current runs of this script based on the script path." > -