From 62786765d63924d13c738110bc3efa4790f25a8d Mon Sep 17 00:00:00 2001 From: Eileen McNaughton Date: Wed, 20 Sep 2023 14:12:24 +1200 Subject: [PATCH] Add hook for 'is_queue_active', 'queue_mainetenance_mode' setting --- CRM/Queue/Queue.php | 14 +++++++++++++- settings/Core.setting.php | 12 ++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/CRM/Queue/Queue.php b/CRM/Queue/Queue.php index 9ad305a928..c8200a80f3 100644 --- a/CRM/Queue/Queue.php +++ b/CRM/Queue/Queue.php @@ -9,6 +9,8 @@ +--------------------------------------------------------------------+ */ +use Civi\Core\Event\GenericHookEvent; + /** * A queue is an object (usually backed by some persistent data store) * which stores a list of tasks or messages for use by other processes. @@ -60,7 +62,17 @@ abstract class CRM_Queue_Queue { */ public function isActive(): bool { $status = CRM_Core_DAO::getFieldValue('CRM_Queue_DAO_Queue', $this->_name, 'status', 'name', TRUE); - // Note: In the future, we may want to incorporate other data (like maintenance-mode or upgrade-status) in deciding active queues. + if ($status === 'active' && \Civi::settings()->get('is_queue_processing_disabled')) { + $status = 'deferred'; + } + $event = GenericHookEvent::create([ + 'status' => &$status, + 'queue_name' => $this->_name, + 'queue_spec' => $this->queueSpec, + ]); + \Civi::dispatcher()->dispatch('civi.queue.isActive', $event); + // Note in future we might want to consider whether an upgrade is in progress. + // Should we set the setting at that point? return ($status === 'active'); } diff --git a/settings/Core.setting.php b/settings/Core.setting.php index 3a7309025b..38819a3e01 100644 --- a/settings/Core.setting.php +++ b/settings/Core.setting.php @@ -1201,4 +1201,16 @@ return [ 'description' => ts('How long should HTTP requests through Guzzle application run for in seconds'), 'help_text' => ts('Set the number of seconds http requests should run for before terminating'), ], + 'is_queue_processing_disabled' => [ + 'name' => 'is_queue_processing_disabled', + 'type' => 'Boolean', + 'default' => FALSE, + 'html_type' => 'yesno', + 'add' => '5.67', + 'title' => ts('Is background queue processing disabled?'), + 'is_domain' => 1, + 'is_contact' => 0, + 'description' => ts('If enabled, CiviCRM will not process background queues.'), + 'help_text' => ts('This setting will only affect sites that have background queue processing enabled (eg. coworker)'), + ], ]; -- 2.25.1