#Scheduled publishing

8 messages · Page 1 of 1 (latest)

plush sundial
#

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?
obtuse hamletBOT
plush sundial
#

Maybe the URL to run this job is api/payload-jobs/run? It doesn't seem to publish the articles.

coral gorge
plush sundial
#

Thanks @coral gorge What URL do I need to hit with the netlity cron to run it?

coral gorge
#

GET https://yoursite.netlify.app/api/payload-jobs/run

#

That should be all that's needed because schedulePublish jobs are queued by the admin UI when an editor sets a date — the Netlify cron just needs to run whatever is already in the queue

plush sundial
#

@coral gorge Thanks very much, that works!