Take the 2-minute tour ×
Drupal Answers is a question and answer site for Drupal developers and administrators. It's 100% free, no registration required.

I've been searching around, but I can not find a good explanation (or understanding) what the 'time' value in hook_cron_queue_info actually does, or how to set it to work properly.

From: https://api.drupal.org/api/drupal/modules!system!system.api.php/function/hook_cron_queue_info/7

it is said that: 'time': (optional) How much time Drupal should spend on calling this worker in seconds. Defaults to 15.

I don't quite understand that. Does calling the worker mean time allowed to execute the cron queue job? And does the next cron queue job starts after this time? Or when the previous job is completed?

share|improve this question
add comment

2 Answers 2

up vote 3 down vote accepted

It's literally what the description says it is - during a cron run, Drupal will spend a maximum of the seconds you provide in that value processing that particular queue, regardless of the number of jobs in it.

If you're looking for the relevant code it's in drupal_cron_run()

foreach ($queues as $queue_name => $info) {
  if (!empty($info['skip on cron'])) {
    // Do not run if queue wants to skip.
    continue;
  }
  $function = $info['worker callback'];
  $end = time() + (isset($info['time']) ? $info['time'] : 15);
  $queue = DrupalQueue::get($queue_name);
  while (time() < $end && ($item = $queue->claimItem())) {
    $function($item->data);
    $queue->deleteItem($item);
  }
}
share|improve this answer
1  
Thanks Clive.I can see where my mix up was. I thought it was time allowed doing ONE job (thinking in case of server time outs). Now I know it is time allowed to do a batch of jobs. –  Quentin Campbell Apr 14 at 8:28
add comment

The answer is obvious if you look at the following two items in combination:

  • 'worker callback': The name of the function to call. It will be called with one argument, the item created via DrupalQueue::createItem().

  • 'time': (optional) How much time Drupal should spend on calling this worker in seconds. Defaults to 15. (my emphasis)

So the optional time value is the maximum time that will spent, during a cron run, to execute the callback worker callback function that you supply in your implementation of this hook.

share|improve this answer
    
OK - somebody seems to think this answer is wrong. Could someone (not necessarely the downvoter) please explain why it is wrong, given what the documentation says? –  Free Radical Apr 14 at 8:05
    
This definitely isn't wrong, can't think why it's been downvoted –  Clive Apr 14 at 8:39
    
I'm not the downvoter ;). Your answer is not wrong but did not answer my question though. And I'm the one that was confused. –  Quentin Campbell Apr 14 at 8:46
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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