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.

Job Queues

default discord avatar
moritzrslast year
4

Why does the autoRun does not work?


I can queue my Job manually using payload.jobs.queue() and then also execute if via the the /payload-jobs/run route.


But it does not schedules itself, although i enabled the shouldAutoRun function.


Any Ideas what i am doing wrong?



tasks: [


{


slug: 'updateAccountTrafficStatistics',


handler: updateAccountTrafficStatistics,


onSuccess: async () => {


console.log('✅ TASK:: updateAccountTrafficStatistics :: SUCCESS')


},


onFail: async () => {


console.log('❌ TASK:: updateAccountTrafficStatistics :: FAILURE')


},


} as TaskConfig<'updateAccountTrafficStatistics'>,


],


workflows: [


{


slug: 'updateAccountTrafficStatisticsWorkflow',


queue: 'every-hour-at-30-minutes',


handler: updateAccountTrafficStatisticWorkflow,


} as WorkflowConfig<'updateAccountTrafficStatisticsWorkflow'>,


],


autoRun: [


{


cron: '30 * * * *', // every 1 hour at 30 minutes past the hour


limit: 100, // limit jobs to process each run


queue: 'every-hour-at-30-minutes', // name of the queue


},


],


shouldAutoRun: async (payload) => {


return true


},

  • default discord avatar
    nclevengerlast year

    are you on vercel/serverless? if so, you may need to start automatically ... i usually do this wrapped by

    waitUntil

    from

    @vercel/functions

    but personally i do kinda hope this is supported automatically in payload eventually

  • default discord avatar
    moritzrslast year

    No. Im working locally inside my docker container

  • default discord avatar
    wkd1079last year

    The docs are way too vague and “autoRun” is deceptively named. It’s up to you to ping the queue. For your use case you can just set up a cron job in docker to hit the api route every X minutes

  • default discord avatar
    moritzrslast year

    I found a workarround, where you queue your workflows in the onInit function and then you requeue it after each workflow execution. This works, but does not feel ideal.

Star on GitHub

Star

Chat on Discord

Discord

online

Can't find what you're looking for?

Get dedicated engineering support directly from the Payload team.