public function CronJobDiscovery::discoverCronJobs in Ultimate Cron 8.2
Automatically discovers and creates default cron jobs.
File
- src/
CronJobDiscovery.php, line 58
Class
- CronJobDiscovery
- Discovery and instantiation of default cron jobs.
Namespace
Drupal\ultimate_cronCode
public function discoverCronJobs() {
// Create cron jobs for hook_cron() implementations.
foreach ($this
->getHooks() as $id => $info) {
$this
->ensureCronJobExists($info, $id);
}
if (!$this->configFactory
->get('ultimate_cron.settings')
->get('queue.enabled')) {
return;
}
// Create cron jobs for queue plugins.
foreach ($this->queueManager
->getDefinitions() as $id => $definition) {
if (!isset($definition['cron'])) {
continue;
}
$job_id = str_replace(':', '__', CronJobInterface::QUEUE_ID_PREFIX . $id);
if (!CronJob::load($job_id)) {
$values = [
'title' => t('Queue: @title', [
'@title' => $definition['title'],
]),
'id' => $job_id,
'module' => $definition['provider'],
// Process queue jobs later by default.
'weight' => 10,
'callback' => 'ultimate_cron.queue_worker:queueCallback',
'scheduler' => [
'id' => 'simple',
'configuration' => [
'rules' => [
'* * * * *',
],
],
],
];
$job = CronJob::create($values);
$job
->save();
}
}
}