Search docs

Jump to any table example

Discord—

Shadcn Job Queue Table

Background jobs as they run: progress, attempts and duration update live, failures retry on their own with backoff, and any job with errors expands to show what went wrong before you retry or cancel it.

$ npx shadcn add https://www.shad-table.dev/r/job-queue-table.json

2 of 2 workers busy · 3 waiting · 1 failed

ErrorsJobStatusProgressAttemptsDurationActions
Send welcome emailsemails · job_8f2a
Succeeded
100% · 1,200 / 1,200
1 / 330s
Sync Stripe customersbilling · job_3c71
Failed
30% · 1,260 / 4,200
3 / 326s
Export invoices (Q3)exports · job_51d0
Running
26% · 900 / 3,400
1 / 36s
Resize product imagesmedia · job_a904
Running
13% · 120 / 860
1 / 32s
Generate payout reportbilling · job_c2e8
Queued
Waiting · 240 items
0 / 3—
Rebuild search indexsearch · job_77b3
Queued
Waiting · 5,000 items
0 / 3—
Send trial remindersemails · job_e015
Queued
Waiting · 300 items
0 / 3—
Purge expired sessionssearch · job_0d6c
Canceled
41% · 7,400 / 18,000
1 / 38s

How it works

1.A job is its attempts

Each job keeps a list of attempts with their start, end, how far they got and the error, if any. Status, the attempts count and the duration are all read from that list, and so is the error history in the expanded row. A real app fills it from whatever the workers report.

src/components/job-queue/data.ts
interface Attempt {
number: number
startedAt: number
endedAt?: number
processed?: number
error?: { code: string; message: string; trace: string[] }
}

2.Failures retry on their own, with backoff

A failed attempt puts the job in Retrying with a countdown (2s, then 4s, then 8s) until it runs out of attempts, and only then is it Failed. Retrying by hand puts it back in the queue with one more attempt allowed. At most two jobs run at once; the one that has waited longest starts next.

src/components/job-queue/queue.ts
return attempt < job.maxAttempts
? { ...job, status: 'retrying', retryAt: now + backoff(attempt) }
: { ...job, status: 'failed' }

3.Rows with errors expand to their history

getRowCanExpand allows expanding only rows that have a failed attempt, including jobs that later succeeded. The detail lists every attempt, newest first, with the error code, message and stack trace, so it is clear whether a retry is worth it.

src/components/job-queue/data-table.tsx
getRowCanExpand: (row) => hasErrors(row.original),
autoResetExpanded: false,

4.Live data without losing your place

The queue updates five times a second, and TanStack resets expanded rows whenever the data changes unless told otherwise. getRowId keys rows by job id and autoResetExpanded: false keeps open rows open. The filter array is memoized so a tick does not count as a filter change.

src/components/job-queue/data-table.tsx
getRowId: (job) => job.id,
autoResetExpanded: false,
autoResetPageIndex: false,

5.One clock for the server and the browser

Durations come from a demo clock that starts at 0 on both the server and the browser, so the first render matches and there is no hydration warning. In your app, pass the server time the data was read at as now, and tick it forward on the client.

src/components/job-queue/index.tsx
const start = (): Queue => ({ now: 0, jobs: seedJobs() })
setQueue((q) => ({ now: q.now + TICK, jobs: tick(q.jobs, q.now + TICK, TICK) }))