feat(scheduler): live admin Scheduler dashboard + reusable poll hook (HU/EN/DE)
New admin Scheduler page (left-nav entry) with a live, self-refreshing view of job activity, queued work and quota. Polling is factored into a reusable useLiveQuery hook (pauses when the tab is unfocused) that the notification bell and future yt-dlp job queue will reuse instead of re-implementing.
This commit is contained in:
parent
02d913f133
commit
db9ee4beab
13 changed files with 491 additions and 5 deletions
22
frontend/src/lib/useLiveQuery.ts
Normal file
22
frontend/src/lib/useLiveQuery.ts
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
import { useQuery, type QueryKey } from "@tanstack/react-query";
|
||||
|
||||
// Reusable "live" polling query: a thin wrapper over react-query that refetches on an
|
||||
// interval and — by leaving refetchIntervalInBackground at its default false — pauses while
|
||||
// the tab is unfocused, so it doesn't poll a server nobody's watching. This is the shared
|
||||
// live-progress mechanism: the Scheduler dashboard uses it now; the notification bell and the
|
||||
// future yt-dlp job queue reuse it rather than each re-implementing polling.
|
||||
export function useLiveQuery<T>(
|
||||
key: QueryKey,
|
||||
queryFn: () => Promise<T>,
|
||||
opts: { intervalMs?: number; enabled?: boolean } = {}
|
||||
) {
|
||||
const { intervalMs = 4000, enabled = true } = opts;
|
||||
return useQuery({
|
||||
queryKey: key,
|
||||
queryFn,
|
||||
enabled,
|
||||
refetchInterval: enabled ? intervalMs : false,
|
||||
refetchIntervalInBackground: false,
|
||||
staleTime: 0,
|
||||
});
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue