strapi-plugin-scheduler icon indicating copy to clipboard operation
strapi-plugin-scheduler copied to clipboard

Convert cron task to object format

Open cpaczek opened this issue 2 years ago • 0 comments

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

cpaczek avatar Feb 16 '23 07:02 cpaczek