I have a cron job that gets stuck because I have a loop claiming items from the queue that ends on numberOfItems() == 0
, which never happens because one of the queue items is stuck and cannot be claimed.
Clearly this is a flaw on my side, but I am trying to understand how to best address it. The claimItem()
method returns FALSE
every time in this case, so it should be easy to handle cases of bad queue processing, for example:
while ($item = $queue->claimItem()) {
// process item
}
However, what if the first queue item is "faulty", while there are other queue items that are perfectly fine? I will never be able to retrieve them in this method. It also seems impossible to move on to the next item in the queue if claimItem()
returns false (please correct me if I am wrong).
What is the correct way to handle such cases with Drupal's queue?