I came across the job scheduler module recently on another job, and it looks quite promising, and means we can drop a lot of code
It has a nice API for get/remove instances too.
Add a job.
$job = array(
'type' => 'story',
'id' => 12,
'period' => 3600,
'periodic' => TRUE,
);
JobScheduler::get('example_unpublish')->set($job);
Work off a job.
function example_unpublish_nodes($job) {
// Do stuff.
}
Remove a job.
$job = array(
'type' => 'story',
'id' => 12,
);
JobScheduler::get('example_unpublish')->remove($job);
Optionally jobs can declared together with a schedule in a hook_cron_job_scheduler_info().
function example_cron_job_scheduler_info() {
$schedulers = array();
$schedulers['example_unpublish'] = array(
'worker callback' => 'example_unpublish_nodes',
'jobs' => array(
array('type' => 'story', 'id' => 12, 'period' => 3600, 'periodic' => TRUE),
)
);
return $schedulers;
}
Jobs can have a 'crontab' instead of a period. Crontab syntax are Unix-like formatted crontab lines.
Example of job with crontab.
// This will create a job that will be triggered from monday to friday, from january to july, every two hours
function example_cron_job_scheduler_info() {
$schedulers = array();
$schedulers['example_unpublish'] = array(
'worker callback' => 'example_unpublish_nodes',
'jobs' => array(
array('type' => 'story', 'id' => 12, 'crontab' => '0 */2 * january-july mon-fri', 'periodic' => TRUE),
)
);
return $schedulers;
}
Comments
Comment #1
sgabe commentedI think this is a good idea, we should definitely look into it.
Comment #2
joachim commentedI am thinking http://drupal.org/project/job_scheduler, with #1372816: Backport the 7.x-2.x branch to a 6.x-2.x - comaintainership request which I am looking into.
It would allow us to schedule jobs with crontab-style syntax, and with some tests for that module, we wouldn't have problems like #1364784: Monthly Interval varies by a few days any more.
Comment #3
dgtlmoon commentedYeah, and i'de love to use something like this so it opens up more possibilities for weird scheduling
Comment #4
dgtlmoon commentedI came across the job scheduler module recently on another job, and it looks quite promising, and means we can drop a lot of code
It has a nice API for get/remove instances too.