Repository navigation
feat(jobs): backfill() — a factory over job(), not a ninth primitive #74
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 4 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
43f0458
feat(jobs): backfill() — a factory over job(), not a ninth primitive
sebyx07 dc80788
feat(jobs): the x_backfills ledger, mirroring x_migrations
sebyx07 838e629
feat(jobs): throttle a backfill, and make its progress readable
sebyx07 06a568a
feat(cli): add backfill generator
sebyx07 efc2f9f
fix(jobs): PR #74 review — ledger completed_at, pacer guard, real tem…
sebyx07 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,77 @@ | ||
| import { describe, expect, test } from 'bun:test'; | ||
|
sebyx07 marked this conversation as resolved.
|
||
| import { staticDevSources } from './data'; | ||
| import type { BackfillFact, JobRunFact } from './facts'; | ||
| import { jobsPanel } from './panel-jobs'; | ||
|
|
||
| const pass = (fact: Partial<BackfillFact> & { runId: string }): BackfillFact => ({ | ||
| name: 'recount-likes', | ||
| status: 'running', | ||
| rows: 0, | ||
| cursor: null, | ||
| startedAt: '2026-08-14T09:00:00.000Z', | ||
| completedAt: null, | ||
| durationMs: null, | ||
| appVersion: '1.2.0', | ||
| ...fact, | ||
| }); | ||
|
|
||
| const run = (fact: Partial<JobRunFact> & { id: string }): JobRunFact => ({ | ||
| job: 'recount-likes', | ||
| queue: 'default', | ||
| status: 'running', | ||
| attempt: 1, | ||
| steps: [], | ||
| ...fact, | ||
| }); | ||
|
|
||
| describe('the jobs panel reports the backfill ledger', () => { | ||
| test('every pass is carried, and only the live ones are counted in flight', async () => { | ||
| const data = await jobsPanel.data( | ||
| staticDevSources({ | ||
| backfills: () => | ||
| Promise.resolve([ | ||
| pass({ runId: 'r3', rows: 12_500, cursor: 'post_12500' }), | ||
| pass({ runId: 'r2', status: 'failed', rows: 400, cursor: 'post_400' }), | ||
| pass({ | ||
| runId: 'r1', | ||
| status: 'completed', | ||
| rows: 84_000, | ||
| completedAt: '2026-08-14T09:04:00.000Z', | ||
| durationMs: 240_000, | ||
| }), | ||
| ]), | ||
| }), | ||
| new URLSearchParams(), | ||
| ); | ||
|
|
||
| // The whole ledger, because "has this ever run here, and what did it sweep" is the panel's | ||
| // question — a filter to `running` would answer it with silence on a finished sweep. | ||
| expect(data.backfills.map((entry) => entry.runId)).toEqual(['r3', 'r2', 'r1']); | ||
| // A failed pass is an attempt the queue will retry, not a sweep in flight. | ||
| expect(data.backfillsInFlight).toBe(1); | ||
| expect(data.backfills[0]?.rows).toBe(12_500); | ||
| expect(data.backfills[0]?.cursor).toBe('post_12500'); | ||
| }); | ||
|
|
||
| test('a ?queue= filter scopes the runs and never the ledger', async () => { | ||
| const sources = staticDevSources({ | ||
| jobRuns: () => | ||
| Promise.resolve([run({ id: 'r3' }), run({ id: 'other', queue: 'mail', job: 'send' })]), | ||
| backfills: () => Promise.resolve([pass({ runId: 'r3' })]), | ||
| }); | ||
|
|
||
| const data = await jobsPanel.data(sources, new URLSearchParams('queue=mail')); | ||
|
|
||
| // A backfill belongs to a table, not to a queue: scoping the ledger by the queue filter would | ||
| // hide the one pass whose job row the same filter just dropped. | ||
| expect(data.runs.map((entry) => entry.id)).toEqual(['other']); | ||
| expect(data.backfills.map((entry) => entry.runId)).toEqual(['r3']); | ||
| expect(data.backfillsInFlight).toBe(1); | ||
| }); | ||
|
|
||
| test('an app that has never swept anything reports an empty ledger, not a failure', async () => { | ||
| const data = await jobsPanel.data(staticDevSources(), new URLSearchParams()); | ||
| expect(data.backfills).toEqual([]); | ||
| expect(data.backfillsInFlight).toBe(0); | ||
| }); | ||
| }); | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.