Simplify your stack and build anything. Or everything.
Build tomorrow’s web with a modern solution you truly own.
Code-based nature means you can build on top of it to power anything.
It’s time to take back your content infrastructure.

Jobs

Now that we have covered Tasks and Workflows, we can tie them together with a concept called a Job.

For example, let's say we have a Workflow or Task that describes the logic to sync information from Payload to a third-party system. This is how you'd declare how to sync that info, but it wouldn't do anything on its own. In order to run that task or workflow, you'd create a Job that references the corresponding Task or Workflow.

Jobs are stored in the Payload database in the payload-jobs collection, and you can decide to keep a running list of all jobs, or configure Payload to delete the job when it has been successfully executed.

Queuing a new job

In order to queue a job, you can use the payload.jobs.queue function.

Here's how you'd queue a new Job, which will run a createPostAndUpdate workflow:

1
const createdJob = await payload.jobs.queue({
2
// Pass the name of the workflow
3
workflow: 'createPostAndUpdate',
4
// The input type will be automatically typed
5
// according to the input you've defined for this workflow
6
input: {
7
title: 'my title',
8
},
9
})

In addition to being able to queue new Jobs based on Workflows, you can also queue a job for a single Task:

1
const createdJob = await payload.jobs.queue({
2
task: 'createPost',
3
input: {
4
title: 'my title',
5
},
6
})
Next

Queues