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.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Erik Frèrejean created an issue. See original summary.

Erik Frèrejean’s picture

I've attached a patch, that updates the queue handling to behave the same way Drupal Core does.

Erik Frèrejean’s picture

Status: Active » Needs review
joelstein’s picture

Status: Needs review » Reviewed & tested by the community
FileSize
551 bytes

I ran into a couple situations where I saw the following errors, and this patch resolved them for me:

  • Error: Unsupported operand types in ultimate_cron/plugins/ultimate_cron/settings/queue.class.php, line 188
  • Notice: Undefined index: ultimate_cron_plugin_settings_queue_cleanup in UltimateCronQueueSettings->cron_alter() (line 188 of ultimate_cron/plugins/ultimate_cron/settings/queue.class.php).

However, it's unnecessary to rename the $function variable. Here's an updated one-line patch.

joelstein’s picture

Doh! Here's the correct patch with the correct variable name.

  • arnested committed 7b3d0dd on 7.x-2.x authored by joelstein
    Issue #2685613 by joelstein, Erik Frèrejean: Queue handling incompatible...
arnested’s picture

Status: Reviewed & tested by the community » Fixed

Added to the 7.x-2.x branch. Thank's for your contribution!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.