Merge bug/scheduler-progress-visibility: live progress for any scheduler job + parallel RSS polling
This commit is contained in:
commit
a004fa4107
9 changed files with 91 additions and 25 deletions
|
|
@ -8,14 +8,22 @@ import { useQuery, type QueryKey } from "@tanstack/react-query";
|
|||
export function useLiveQuery<T>(
|
||||
key: QueryKey,
|
||||
queryFn: () => Promise<T>,
|
||||
opts: { intervalMs?: number; enabled?: boolean } = {}
|
||||
// intervalMs may be a function of the latest data, so the poll cadence can adapt to it
|
||||
// (e.g. poll faster while a job is running). react-query re-evaluates it after each fetch
|
||||
// against fresh data — the right place for this, vs. a React state toggle that can lag or
|
||||
// stall the live updates.
|
||||
opts: { intervalMs?: number | ((data: T | undefined) => number); enabled?: boolean } = {}
|
||||
) {
|
||||
const { intervalMs = 4000, enabled = true } = opts;
|
||||
return useQuery({
|
||||
queryKey: key,
|
||||
queryFn,
|
||||
enabled,
|
||||
refetchInterval: enabled ? intervalMs : false,
|
||||
refetchInterval: !enabled
|
||||
? false
|
||||
: typeof intervalMs === "function"
|
||||
? (query) => intervalMs(query.state.data as T | undefined)
|
||||
: intervalMs,
|
||||
refetchIntervalInBackground: false,
|
||||
staleTime: 0,
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue