I'm implementing a basic blog with scheduled publishing. Going through the docs but I'm still confused about how to set it up. Is there anywhere with a simple example?
Where I'm at now is that I have a task defined in payload.config.js
jobs: {
tasks: [
{
slug: 'publishScheduled',
schedule: [{ cron: '* * * * *', queue: 'articles'}],
handler: async ({ req, input }) => {
// Find scheduled docs and publish them
return {
output: 'Scheduled articles processed',
}
}
}
]
}
Payload provides a few options for running tasks, and I think the best one for my company's setup is to call a URL. I think the URL I need to use is, localhost:3000/api/payload-jobs/run?queue=articles. Is that right?
I am confused about a few things
- If we use something else to just run the task when the URL is visited, then the
cron: '* * * * *'part in the task definition seems redundant. Will it being there as well cause problems? Should I just be removed? Or should I define the task in a different way? - I can't seem to find any Payload CMS API method endpoint that publishes scheduled articles. (i.e.
payload.jobs.publishScheduled()(Made up example). ChatGPT seems to think I need to do a manual DB query to pull all articles scheduled to publish before the current date, and update the records manually etc, but it seems hacky. Is there no offical API method to do this?