feat: adds new jobs.shouldAutoRun property (#11092)

Adds a `shouldAutoRun` property to the `jobs` config to be able to have
fine-grained control over if jobs should be run. This is helpful in
cases where you may have many horizontally scaled compute instances, and
only one instance should be responsible for running jobs.
This commit is contained in:
James Mikrut
2025-02-10 16:43:20 -05:00
committed by GitHub
parent d2fe9b0807
commit 5dadccea39
4 changed files with 53 additions and 21 deletions

View File

@@ -29,7 +29,7 @@ As mentioned above, you can queue jobs, but the jobs won't run unless a worker p
#### Cron jobs
You can use the jobs.autoRun property to configure cron jobs:
You can use the `jobs.autoRun` property to configure cron jobs:
```ts
export default buildConfig({
@@ -47,6 +47,12 @@ export default buildConfig({
},
// add as many cron jobs as you want
],
shouldAutoRun: async (payload) => {
// Tell Payload if it should run jobs or not.
// This function will be invoked each time Payload goes to pick up and run jobs.
// If this function ever returns false, the cron schedule will be stopped.
return true
}
},
})
```