2

I'm trying to use queue api with cron, everything seems work but drupal does not enter on the "worker" function. The problem there is only if I enable Elysia Cron (and I've to enable it..)

<?php 

/**
 * Implements hook_cron_queue_info().
 */
function monitor_import_cron_queue_info() {
  $queue['monitor_import_queue'] = array(
    'worker callback' => 'monitor_import_queue_worker',
    'time' => 10,
  );
  return $queue;
}

/**
 * Implements hook_cron().
 */
function monitor_import_cron() {

  $call = new MyWS();
  $params = new getSoggettoView();
  $params->limit = '10'; //$limit;
  $params->offset = '0';
  $results = $call->getSoggettoView($params);
  $items = $results->return;
  $queue = DrupalQueue::get('monitor_import_queue'); // grab queue
  $queue->createQueue(); // initialize
  foreach ($items as $item) {
    $queue->createItem($item);
  }
}

/**
 * Worker callback
 *
 * @see mymodule_cron_queue_info().
 */
function monitor_import_queue_worker($item) {
  $a = 1;
}
2
  • 1
    If $call->getSoggettoView($params); doesn't return any data to add to the queue, then the worker callback won't get an item to process, i.e won't be called. Commented Apr 7, 2014 at 9:49
  • The problem seems elysia_cron
    – arrubiu
    Commented Apr 7, 2014 at 13:07

1 Answer 1

1

Below code perfectly works for me...

/**
 * Implements hook_cron_queue_info().
*/
function drup_custom_cron_queue_info() {
  $queue['drup_custom_queue'] = array(
      'worker callback' => 'drup_custom_queue_worker',
      'time' => 10,
  );
  return $queue;
}

/**
 * Implements hook_cron().
 */
function drup_custom_cron() {
  $items = array('1', '2', '3', '4', '5', '6', '7');
  $queue = DrupalQueue::get('drup_custom_queue'); // grab queue
  foreach ($items as $i) {
    $item = new stdClass();
    $item->created = time();
    $item->sequence = $i;
    $queue->createItem($item);
  }
}

/**
 * Worker callback
 *
 * @see mymodule_cron_queue_info().
 */
function drup_custom_queue_worker($item) {
  watchdog('drup_custom', 'Queue worker processed item with @sequence created at @time',
    array(
      '@sequence' => $item->sequence,
      '@time' => date_iso8601($item->created),
    )
  );
}

Check your custom callback which returns results as mentioned by David in comment..

2
  • It doesn't work :( I've simply changed hook names with my module name. It's a problem if I call my custom logic simply after $queue->createItem($item), not passing from worker callback?
    – arrubiu
    Commented Apr 7, 2014 at 12:48
  • Mh, I'm using elysia_cron, the problem seems it, without elysia the function works.
    – arrubiu
    Commented Apr 7, 2014 at 13:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.