README

Gives developers an ability to configure cron-like tasks through the code.

This module intentionally doesn't surface any of the configuration or logs
to the CMS, being of an opinion these tasks belong with developers and sysadmins.
If you want that, see the "CMS-driven scheduler" section below.

What problem does module solve?

Developers don't always have access to the server to configure cronjobs,
and instead they have to rely on server administrators to do it for them.
This can slow down development cycles, and can lead to misunderstandings and
misconfigurations if cronjobs are set up by hand.

This module solves this by getting the sysadmin to set up a single generic
cronjob on the server side, and delegate the actual job definition to the
PHP code.

CMS-driven scheduler

If you are looking for CMS-controllable scheduler, please check out
the queuedjobs module.
Here are some examples of how to implement recurring jobs with that module:

Run ./framework/sake dev/build flush=1 to make SilverStripe aware of the new
module.

Then execute the crontask controller, it's preferable you do this via the CLI
since that is how the server will execute it.

./framework/sake dev/cron

Server configuration

Linux and Unix servers often comes installed with a cron daemon that are running
commands according to a schedule. How to configure these can vary a lot but the
most common way is by adding a file to the /etc/cron.d/ directory.

This will run every minute as the www-data user and check if there are any
outstanding tasks that needs to be executed.

Warning: Observe that the crontask module doesn't to any scheduling. If the
run time is more than one minute, it might start another process that interferes
with the still running process. You can either trigger the dev/cron task less
often or use something like sera.

The getSchedule() method

The crontask controller expects that the getSchedule returns a string as a cron
expression.

Some examples:

* * * * * - every time

*/5 * * * * - every five minute (00:05, 00:10, 00:15 etc)

0 1 * * * - every day at 01:00

0 0 2 * * - the 2nd of every month at 00:00

0 0 0 ? 1/2 FRI#2 * - Every second Friday of every other month at 00:00

Example:

public function getSchedule() {
return "0 1 * * *";
}

The process() method

The process method will be executed only when it's time for a task to run
(according to the getSchedule method). What you do in here is up to you. You can
either do work in here or for example execute BuildTasks run() methods.