Chain Deletion
Delete chains with blocker safety.
Chains can be deleted using deleteChains (plural) or deleteChain (singular). All jobs in the chain, its head job and continuations, are removed together:
src/chain-deletion.ts
const deletedChains = await stateAdapter.withTransaction(async (txCtx) =>
client.deleteChains({ ...txCtx, ids: [chain.id] }),
);When a deleted chain has a running job, its complete throws JobNotFoundError. The attempt is also notified as lost, and its handler's signal aborts once the notification reaches the worker runner, which happens when the runner was built from the deleting client or both share a notify adapter. If the attempt is inside a fenced transaction, the delete waits for it to end, except on Redis, where the transaction that commits second runs again rather than waiting.
Use deleteChain to target a single chain — it returns the deleted chain or undefined if no chain with that ID exists. deleteChains silently skips missing IDs and returns the chains that were actually deleted. Both calls are idempotent: deleting the same chain again returns undefined from deleteChain and [] from deleteChains:
src/chain-deletion.ts
const deletedAgain = await stateAdapter.withTransaction(async (txCtx) =>
client.deleteChain({ ...txCtx, id: chain.id }),
);Blocker Safety
Before deleting, the system checks whether any external chain depends on the target chains as blockers. "External" means the dependent job's own chain is not in the deletion set. This prevents orphaning blocked chains that would never unblock. Deleting a fetch-data chain on its own is rejected with BlockerReferenceError, because generate-report still references it:
src/chain-deletion.ts
const deleteBlockerOnly = stateAdapter.withTransaction(async (txCtx) =>
client.deleteChains({ ...txCtx, ids: [fetchChains[0].id] }),
);Deleting a Chain with Its Blockers
Deletion never follows blocker relationships on its own. To remove a chain together with the chains it waits on, collect its blocker chains with getJobBlockers and pass them in the same deleteChains call:
src/chain-deletion.ts
const deletedWithBlockers = await stateAdapter.withTransaction(async (txCtx) => {
const blockerChains = await client.getJobBlockers({ ...txCtx, jobId: reportChain.id });
return client.deleteChains({
...txCtx,
ids: [reportChain.id, ...blockerChains.map((blocker) => blocker.id)],
});
});getJobBlockers takes a job ID: a chain's head job has the chain's ID, and a continuation declared with its own blockers has to be queried separately (list the chain's jobs with listChainJobs). Repeat the lookup on each blocker chain to reach blockers of blockers. If any chain in the set is still a blocker of a job outside it — for example, a blocker shared with another report — the call throws BlockerReferenceError and deletes nothing; leave that chain out, or add its dependents to the set.
What Gets Deleted
Given a list of ids, the operation deletes all jobs in each chain (every job where job.chainId matches a provided ID, including the head and continuations), together with the blocker references those jobs hold on other chains. References pointing at a deleted chain from a job outside the deletion set are never removed — they make the whole deletion fail.
See examples/guides/src/chain-deletion.ts for the runnable code. See also Tx Hooks and Job Blockers.