3

I have set up a queue using:

  function custom_logger_cron_queue_info()
  {
    $queues['custom_logger'] = array(
      'worker callback' => 'custom_logger_import',
      'time' => 60,
    );
    return $queues;
  }

Which I add items to using:

$item = array('uri' => $uri, 'uid' => $uid, 'fid' => $fid);
$queue = DrupalQueue::get('custom_logger');
$queue->createItem($item);

Which is working great, except that when cron runs every minute for this queue (I am using ultimate_cron module to set this) the custom_logger_import function is only processing one item per run. At present I have the function simply set up as:

function custom_logger_import($item) {
    $uri = $item['uri'];
    $uid = $item['uid'];
    $fid = $item['fid'];
//Do some stuff
}

Is there something I am missing on ensuring that as many items as possible get run? They are only small jobs that complete in less than a couple seconds but at the moment its taking 3-4 minutes to process just 3 items.

UPDATE:

The problem was actually in my function that was being called. I was using non-drupal friendly sql which seemed to prevent the job being done more than once. After updating all the database related stuff to drupal friendly database extraction layer stuff, it all works fine. For the record, here is a good way of checking that everything is running fine with the queues. Comment out your function being called by the queue and add this in replacement:

$file = '/somepath/hello.txt';
$current = file_get_contents($file);
$current .= $item['some variable from your queue item'] . " Hello\n";
file_put_contents($file, $current);

Then, when the queue is processed at cron, it should print out each of your queue items variable followed by hello to a text file.

3

The queue system is designed to process items until the time is up. Maybe it's a bug in Ultime Cron? Try running the default core cron.php to verify that.

Are you sure that you're actually adding multiple items to be processed? Check your queue table.

  • Thanks for the answer, the problem was actually in my code and I will update my question with the fixes I made. – 7wonders Mar 12 '12 at 10:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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