From: Tim Otten Date: Wed, 20 Jul 2022 07:42:36 +0000 (-0700) Subject: CRM_Queue_Task - Fire internal events X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=ec144b443304ad05efad81f261a918ddd647e41b;p=civicrm-core.git CRM_Queue_Task - Fire internal events --- diff --git a/CRM/Queue/Task.php b/CRM/Queue/Task.php index da73d76379..55817fae44 100644 --- a/CRM/Queue/Task.php +++ b/CRM/Queue/Task.php @@ -76,6 +76,11 @@ class CRM_Queue_Task { * FALSE or exception if task fails. */ public function run($taskCtx) { + Civi::dispatcher()->dispatch('civi.queue.runTask.start', \Civi\Core\Event\GenericHookEvent::create([ + 'task' => $this, + 'taskCtx' => $taskCtx, + ])); + $args = $this->arguments; array_unshift($args, $taskCtx); @@ -91,12 +96,20 @@ class CRM_Queue_Task { } } - if (is_callable($this->callback)) { - $result = call_user_func_array($this->callback, $args); - return $result; + try { + if (is_callable($this->callback)) { + $result = call_user_func_array($this->callback, $args); + return $result; + } + else { + throw new Exception('Failed to call callback: ' . $this->getSummary()); + } } - else { - throw new Exception('Failed to call callback: ' . $this->getSummary()); + finally { + Civi::dispatcher()->dispatch('civi.queue.runTask.finally', \Civi\Core\Event\GenericHookEvent::create([ + 'task' => $this, + 'taskCtx' => $taskCtx, + ])); } }