Running queues following the docs' example might lead to infinite loops
Following the Queue Reference example for running a queue in CRM_Queue_Runner::ERROR_CONTINUE
mode with a while
loop that only break
s for is_continue!=1
will lead to infinite loops when a queue item has not been released yet (e.g. due to the script terminating without an exception being caught and the queue being re-run before release of the next item).
That's because CRM_Queue_Queue_Sql::claimItem()
fetches the first queue item and filters for release_time
afterwards - yielding no result, but reporting more items to be in the queue (is_continue=1
). The only way to catch these cases with code calling the CRM_Queue_Runner::runNext()
method is to check for is_error=1
and the exception
message being Failed to claim next task
.
So, I've got some questions regarding Queues:
- Is there any best practice for handling errors during
claimItem()
any better? - Would you agree there should be another indicator in the task result for those cases, or maybe that exception actually being thrown?
- Alternatively, should
is_continue
be0
instead for those cases (i.e. its meaning would change from queue finished to queue processing can continue)? - Can the
$lease_time
parameter for SQL queues'claimItem()
be exposed to all queues, so that the caller can modify it?
I see that the query was altered with https://github.com/civicrm/civicrm-core/pull/15421 by @artfulrobot