mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-04-24 16:29:45 +00:00
feat: periodically re-poll queue progress state (#9136)
## Summary - Add `useQueuePolling` composable that polls `queueStore.update()` every 5s while jobs are active - Calls `update()` immediately on creation so the UI is current after page reload - Uses `useIntervalFn` + `watch` pattern (same as `assetDownloadStore`) to pause/resume based on `activeJobsCount` ## Related Issue - Related to #8136 ## QA - Queue a prompt, reload page mid-execution, verify queue UI updates every ~5s - Verify polling stops when queue empties - Verify polling resumes when new jobs are queued ┆Issue is synchronized with this [Notion page](https://www.notion.so/PR-9136-feat-periodically-re-poll-queue-progress-state-3106d73d36508119a32fc5b9c8eda21c) by [Unito](https://www.unito.io)
This commit is contained in:
committed by
GitHub
parent
e333ad459e
commit
78fe639540
47
src/platform/remote/comfyui/useQueuePolling.ts
Normal file
47
src/platform/remote/comfyui/useQueuePolling.ts
Normal file
@@ -0,0 +1,47 @@
|
||||
import { useTimeoutFn } from '@vueuse/core'
|
||||
import { ref, watch } from 'vue'
|
||||
|
||||
import { useQueueStore } from '@/stores/queueStore'
|
||||
|
||||
const BASE_INTERVAL_MS = 8_000
|
||||
const MAX_INTERVAL_MS = 32_000
|
||||
const BACKOFF_MULTIPLIER = 1.5
|
||||
|
||||
export function useQueuePolling() {
|
||||
const queueStore = useQueueStore()
|
||||
const delay = ref(BASE_INTERVAL_MS)
|
||||
|
||||
const { start, stop } = useTimeoutFn(
|
||||
() => {
|
||||
if (queueStore.activeJobsCount !== 1 || queueStore.isLoading) return
|
||||
delay.value = Math.min(delay.value * BACKOFF_MULTIPLIER, MAX_INTERVAL_MS)
|
||||
void queueStore.update()
|
||||
},
|
||||
delay,
|
||||
{ immediate: false }
|
||||
)
|
||||
|
||||
function scheduleNextPoll() {
|
||||
if (queueStore.activeJobsCount === 1 && !queueStore.isLoading) start()
|
||||
else stop()
|
||||
}
|
||||
|
||||
watch(
|
||||
() => queueStore.activeJobsCount,
|
||||
() => {
|
||||
delay.value = BASE_INTERVAL_MS
|
||||
scheduleNextPoll()
|
||||
},
|
||||
{ immediate: true }
|
||||
)
|
||||
|
||||
// Reschedule after any update completes (whether from polling or
|
||||
// WebSocket events) to avoid redundant requests.
|
||||
watch(
|
||||
() => queueStore.isLoading,
|
||||
(loading, wasLoading) => {
|
||||
if (wasLoading && !loading) scheduleNextPoll()
|
||||
},
|
||||
{ flush: 'sync' }
|
||||
)
|
||||
}
|
||||
Reference in New Issue
Block a user