0

I am trying to figure out how Drupal pulls what will be the next item to be processed in the queue for Drupal 7. I have looked at SystemQueue::claimItem and I am missing something. I have a queue that jams from time to time and I do not know how to figure out what record it is jamming on.

Thanks, Steve

3
  • Why not add watchdog('mymodule', 'Starting [insert id here]'); and watchdog('mymodule', 'Completing [insert id here]'); to the start and end of the processing callback? That would let you know pretty quickly which item was started and not finished. You could even add the ids/timestamps/status to a custom database table, then add a cron job to notify you if one hasn't finished after x amount of time
    – Clive
    Commented Mar 5, 2018 at 20:17
  • It is not getting that far. My function starts like this - function _module_participant_upload_queue($entity_array_enqueued) { $start_time_queue = microtime(true); $nid_from_queue = $entity_array_enqueued['nid']; watchdog('module_participant_upload_queue', 'Starting Queue for NID ' . $nid_from_queue);
    – Steve
    Commented Mar 6, 2018 at 17:16
  • If it's not getting that far then it's not processing any items at all and you probably need to debug further up the chain
    – Clive
    Commented Mar 6, 2018 at 17:18

1 Answer 1

0

SystemQueue::claimItem has the code you're looking for. https://api.drupal.org/api/drupal/modules%21system%21system.queue.inc/function/SystemQueue%3A%3AclaimItem/7.x

You can run the same query that will be used to get the next item in the queue. Just replace $this->name in the code below with the queue name.

    $item = db_query_range('SELECT data, item_id FROM {queue} q WHERE expire = 0 AND name = :name ORDER BY created, item_id ASC', 0, 1, array(
      ':name' => $this->name,
    ))
      ->fetchObject();

$item should have everything you're looking for.

3
  • That is what I had thought...this is where I am getting lost. If I do the query select count(*) from queue where name = 'module_participant_upload_queue'; I get 800 results. But If I do the query above I do not get back any results. There is the loop for managing expiration right under the code block you posted.
    – Steve
    Commented Mar 6, 2018 at 17:13
  • If you run select data, item_id from queue where name = 'module_participant_upload_queue' LIMIT 10; what do you get? The only reason count(*) should return something but the query above doesn't would be if expire isn't set to 0. Commented Mar 6, 2018 at 23:14
  • How is this going? Was this helpful? Commented Mar 11, 2018 at 15:57

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.