Problem/Motivation
The README gives this example for declaring a job inside hook_cron_job_scheduler_info():
// 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 = [];
$schedulers['example_unpublish'] = [
'worker callback' => 'example_unpublish_nodes',
'jobs' => [
['type' => 'story', 'id' => 12, 'crontab' => '0 */2 * january-july mon-fri', 'periodic' => TRUE],
],
];
return $schedulers;
}
So I configured a job in my module, made sure that the worker callback is a valid function, and then rebuilt the cache. However, I don't see the job in the job schedule
table in the database.
I also tried re-installing my custom module, but the jobs did not get added.
If I create a job using the service like this:
$job = [
'name' => 'example_unpublish',
'type' => 'story',
'id' => 12,
'period' => 3600,
'periodic' => TRUE,
];
$service = \Drupal::service('job_scheduler.manager');
$service->set($job)
then the job is created and saved in the database.
So what do I need to do to "activate" (create in the database) the jobs that I defined in hook_cron_job_scheduler_info()?
Steps to reproduce
My actual code:
function MYMODULE_cron_job_scheduler_info() {
$schedulers = [];
$schedulers['MYMODULE_notifications_by_interval'] = [
'worker callback' => 'MYMODULE_notifications_by_interval',
'jobs' => [
['type' => 'notifications', 'id' => 0000, 'crontab' => '0 0 * * *', 'periodic' => TRUE],
['type' => 'notifications', 'id' => 0015, 'crontab' => '15 0 * * *', 'periodic' => TRUE],
['type' => 'notifications', 'id' => 0030, 'crontab' => '30 0 * * *', 'periodic' => TRUE],
['type' => 'notifications', 'id' => 0045, 'crontab' => '45 0 * * *', 'periodic' => TRUE],
['type' => 'notifications', 'id' => 0100, 'crontab' => '0 1 * * *', 'periodic' => TRUE],
['type' => 'notifications', 'id' => 0115, 'crontab' => '15 1 * * *', 'periodic' => TRUE],
['type' => 'notifications', 'id' => 0130, 'crontab' => '30 1 * * *', 'periodic' => TRUE],
['type' => 'notifications', 'id' => 0145, 'crontab' => '45 1 * * *', 'periodic' => TRUE],
['type' => 'notifications', 'id' => 1200, 'crontab' => '0 12 * * *', 'periodic' => TRUE],
]
];
return $schedulers;
}