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.