4

I have set up a queue using this code.

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

  return $queues;
}

I add items using this code.

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

It works great, except that when cron runs every minute for this queue (I am using the Ultimate Cron module to set this) the custom_logger_import() is only processing one item per run.

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

Is there something I am missing on ensuring that more items are handled? 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.

2 Answers 2

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.

0
2

If you want to do it programmatically instead of cron job, then this could be one of the option -

$queue_machine_name = 'custom_logger';
$queue = \Drupal::queue($queue_machine_name); 
$queue_worker = \Drupal::service('plugin.manager.queue_worker')->createInstance($queue_machine_name);
$item_ids = ['1','2','3'];
foreach ($item_ids as $item){
  $queue_worker->processItem($item_id);  
}


Your Answer

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

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