hook_civicrm_QueueActive¶
Summary¶
Hook to inform background queue processor not to process items.
This hook is called when a background process attempts to claim an item from the queue to process. A hook could alter the status from 'active' to denote that the server is busy & hence no item should be claimed and processed at this time.
Definition¶
hook_civicrm_QueueActive(string &$status, string $queueName, array $queueSpecification) : void
Parameters¶
- @param string $status This will be set to active. It is recommended hooks change it to 'paused' to prevent queue processing (although currently any value other than active is treated as inactive 'paused')
- @param string $queueName The name of the queue. Equivalent to civicrm_queue.name
- @param array $queueSpecification Array of information about the queue loaded from civicrm_queue.
Availability¶
From 5.67
Example¶
my_extension_civicrm_QueueActive(string &$status): void {
$threshold = (int) \CRM_Utils_Constant::value('busy_threshold', 500);
if (!$threshold) {
return;
}
$thresholdNumberOfMinutes = (int) \CRM_Utils_Constant::value('busy_threshold_minutes', 5);
$countOfContributionsInTimeFrame = \CRM_Core_DAO::singleValueQuery(
' SELECT COUNT(*) FROM log_civicrm_contribution WHERE log_date > DATE_SUB(NOW(), INTERVAL %1 MINUTE)',
[1 => [$thresholdNumberOfMinutes, 'Integer']]
);
if ($countOfContributionsInTimeFrame > $threshold) {
\Civi::log('queue')->info(
"Early return as queue is backed up. $countOfContributionsInTimeFrame contributions in the last $thresholdNumberOfMinutes"
. " minutes is greater than the threshold of $threshold"
);
$status = 'busy';
}
}