DEV Community

Kacper Zawojski
Kacper Zawojski

Posted on

Payload v4: jobs always run at depth 0, with no collection hooks

A v4 migration gotcha for anyone using Payload's job queue.

jobs.depth and jobs.runHooks were removed. Tasks now signal their result by throwing — not via a state field, which is gone:

// v3 (no longer works)
const myTask: TaskHandler<'MyTask'> = async ({ input }) => {
  if (!input.id) return { state: 'failed', errorMessage: 'Missing id' }
  return { state: 'succeeded', output: { ok: true } }
}

// v4
const myTask: TaskHandler<'MyTask'> = async ({ input }) => {
  if (!input.id) throw new Error('Missing id')  // throw = fail + retry
  return { output: { ok: true } }
}
Enter fullscreen mode Exit fullscreen mode

Jobs always run at depth: 0 now, which means they operate on raw relationship IDs and skip collection hooks. It's faster and far more predictable — no surprise side effects from a hook firing deep inside a background task.

Top comments (0)