Table of Contents
Recurring jobs on SilverStripe Platform are managed in one of two ways - the CronTask module, or as a server-defined cronjob.
Using a CronTask
As part of using SilverStripe Platform, you should already have the silverstripe/crontask module installed. The dev/cron cron task is automatically set-up on your stack and utilises sera in order to ensure that only one server will run the task at any one time, regardless of how many servers are in-use on the current environment. This is important to note if you are migrating from a non-distributed system. See the CronTask docs for guidance on creating a new CronTask.
Using a CronJob
Starting with SilverStripe Platform version 3.3.0, you are able to define cronjobs in your
.platform.yml file like so:
crons: every_server_task: time: "0 20 * * *" sake_all: "dev/tasks/MyTask" vhost: "mysite" try_for_the_lock_task: time: "1 21 * * *" sake_once: "dev/tasks/MySecondTask" vhost: "mysite"
In the example above, the first task will be run once a day, and on each server in the environment because it uses
sake_all. In some cases this may be one server; in others, up to 16. Make sure you take this into consideration when adding a cronjob to your
.platform.yml file, as running the same task from multiple boxes at the same time can cause race conditions and other issues.
The second task will also be run once a day, but only on at most one server because it uses
The cron always runs as the web user
www-data. You can read more about cronjobs in the .platform.yml documentation
Please note that this is a more advanced option for configuration - if you have any questions at all, please don’t hesitate to contact the support team.