-
Notifications
You must be signed in to change notification settings - Fork 2
Cronjobs
OTF has its own built-in cron scheduler. This is to provide the developer with more direct control of the scheduling of jobs, and to make implementation and deployment easier.
In your crontab on your server, you only need to register a single job that runs every minute. It should be a CURL request to http://your-otf-site.com/ot/cronjob
Your public guest user needs to have access to this endpoint otherwise the job will fail.
OTF adds a resource type so that you can store your cronjobs in the modules folder where they belong. Just like DbTable, Controller, etc., Cronjob is stored in /application/modules/yourmodule/cronjobs and will be prefixed like other attributes, such as Yourmodule_Cronjob_Myjob.
Your cronjob should implement Ot_Cron_JobInterface.
You must register the cronjob to run via the cronjob register.
public function _initCronjobs()
{
$cronjobs = array();
$cronjobs[] = new Ot_Cron_Job('Ot_EmailQueue', 'Email Queue', 'Processes emails from the queue', '* * * * *', 'Ot_Cronjob_EmailQueue');
$register = new Ot_Cron_JobRegister();
$register->registerJobs($cronjobs);
}
Each cron job is setup so that it only runs one copy of each job at a time. To prevent multiple jobs from running, a lock file is created in the /cache folder of your OTF app. The lock file is named {cronjobname}.lock. As long as this lock file exists, additional jobs will not run.
In some cases, an error may occur during the cron job execution that will leave this remnant file in the cache folder, thus preventing the job from continuing to run. Deleting this file will allow the job to execute again.