Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert cron task to object format #30

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

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