Strapi cron jobs just for production environment?

Two things to keep in mind (one to only run in production)

  • Crons are executed based on the server’s timezone which should almost always be exclusively UTC, meaning your cron timing should be based on the fact it’s running in UTC (there is an open PR to address running them in a specific timezone here:

https://github.com/strapi/strapi/pull/8373

  • You can specify in the cron using an if() {} statement to check the current NODE_ENV as we do not have specific cron files for each environment.

Please do note that if you plan to use any clustering at all not just PM2 instance clustering, but also any higher level load balancing such as Nginx as a proxy for a cluster of Strapi backend servers, you should not use the built in Strapi cron function. This would lead to multiple servers running the same action at the same time and thus cause a race condition that could cause corruption/errors/unexpected results.

In place of something like that, I would recommend you build a custom route/controller to run the code and setup an external cron script, maybe using something like node-cron running either in PM2 itself, or even something serverless like an AWS lambda function.