Skip to content

Conversation

@cpaczek
Copy link

@cpaczek cpaczek commented Feb 16, 2023

I converted the cron task to object format so it can integrate with my plugin: https://github.com/excl-networks/strapi-plugin-redcron

This is fully supported by Strapi as you can see here: https://docs.strapi.io/developer-docs/latest/setup-deployment-guides/configurations/optional/cronjobs.html

This will allow people who are horizontally scaling strapi to prevent race conditions. (i.e only 1 strapi instance will run the cron job.

Also not sure if you knew this but you can programmatically add cron jobs in the bootstrap function. This could make it easier for users to configure the plugin.

strapi.cron.add({
      myJob: {
        task: async ({ strapi }) => {
          console.log("hello from bootstrap")
        },
        options: {
            rule: '*/10 * * * * *',
        }
      },
    })

See: https://docs.strapi.io/developer-docs/latest/developer-resources/plugin-api-reference/server.html#cron

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant