Skip to content

Add support for job dependencies in pg boss#747

Open
klesgidis wants to merge 1 commit intotimgit:masterfrom
klesgidis:master
Open

Add support for job dependencies in pg boss#747
klesgidis wants to merge 1 commit intotimgit:masterfrom
klesgidis:master

Conversation

@klesgidis
Copy link
Copy Markdown
Contributor

Summary

Add first-class job dependencies to pg-boss — a job can declare dependsOn parent jobs and won't be fetched until all parents complete. Enables fan-in and pipeline patterns without application-level orchestration.

What changed

  • dependsOn option on send() / insert() — dependent jobs are inserted as blocked = true, invisible to fetch
  • job_dependency table — normalized parent/child tracking with efficient indexes for both directions
  • Automatic unblocking — CTE in completeJobs checks and unblocks children when all parents are done (no-op for queues without dependencies)
  • blocking flag on parent jobs — lets the completion CTE short-circuit
  • Updated job_i5 fetch index — adds AND NOT blocked at the index level, zero cost for non-dependent jobs
  • getDependencies() / getDependents() — query the dependency graph
  • Validation, cleanup, migration v30→v31 — all additive, no breaking changes

Usage

const jobA = await boss.send('process-data', { file: '1.csv' })
const jobB = await boss.send('process-data', { file: '2.csv' })

// jobC won't start until both jobA and jobB complete
const jobC = await boss.send('aggregate-results', { output: 'report.csv' }, {
  dependsOn: [
    { name: 'process-data', id: jobA },
    { name: 'process-data', id: jobB }
  ]
})

// query the graph
const parents = await boss.getDependencies('aggregate-results', jobC)
const children = await boss.getDependents('process-data', jobA)

Resolves #745

@coveralls
Copy link
Copy Markdown

coveralls commented Apr 2, 2026

Coverage Status

coverage: 100.0%. remained the same
when pulling fb7a8e7 on klesgidis:master
into a827ec4 on timgit:master.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Proposal: First-class job dependency support

2 participants