There is an incompatibility between the Drupal core handling of queues in a cron task and the way Ultimate cron handles them.
I use the following queue definition:
/**
* Implements hook_cron_queue_info().
*/
function km_dashboard_cron_queue_info() {
$queues = array();
$queues[KM_DASHBOARD_MAILQ] = array(
'worker callback' => array(
'\KennisMeester\Dashboard\Queue\MailWorker',
'run',
),
'time' => 60,
);
return $queues;
}
Using X Autoload we assure that the callback can be include whenever needed. This works because drupal core uses the following snippet to run the queues (common.php - line: 5384)
foreach ($queues as $queue_name => $info) {
if (!empty($info['skip on cron'])) {
// Do not run if queue wants to skip.
continue;
}
$callback = $info['worker callback'];
$end = time() + (isset($info['time']) ? $info['time'] : 15);
$queue = DrupalQueue::get($queue_name);
while (time() < $end && ($item = $queue->claimItem())) {
try {
call_user_func($callback, $item->data);
$queue->deleteItem($item);
}
catch (Exception $e) {
// In case of exception log it and leave the item in the queue
// to be processed again later.
watchdog_exception('cron', $e);
}
}
}
The worker callback is passed through call_user_func
, which correctly will make the static call. Ultimate cron however uses
try {
$function($item->data);
$queue->deleteItem($item);
$items++;
// Sleep after processing retrieving.
if ($settings['queue']['item_delay']) {
usleep($settings['queue']['item_delay'] * 1000000);
}
}
Which enforces the callback to be a string which is directly executed, and therefore breaking a callback that is accepted by the core.
Comment | File | Size | Author |
---|---|---|---|
#5 | ultimate_cron-queue-callback-2685613-5.patch | 551 bytes | joelstein |
#4 | ultimate_cron-queue-callback-2685613-4.patch | 551 bytes | joelstein |
#2 | cron_queue_handeling_consistently-2685613-2.patch | 991 bytes | Erik Frèrejean |
Comments
Comment #2
Erik FrèrejeanI've attached a patch, that updates the queue handling to behave the same way Drupal Core does.
Comment #3
Erik FrèrejeanComment #4
joelstein CreditAttribution: joelstein commentedI ran into a couple situations where I saw the following errors, and this patch resolved them for me:
However, it's unnecessary to rename the
$function
variable. Here's an updated one-line patch.Comment #5
joelstein CreditAttribution: joelstein commentedDoh! Here's the correct patch with the correct variable name.
Comment #7
arnested CreditAttribution: arnested at Reload commentedAdded to the 7.x-2.x branch. Thank's for your contribution!