CRM_Queue_Task - Fire internal events
authorTim Otten <totten@civicrm.org>
Wed, 20 Jul 2022 07:42:36 +0000 (00:42 -0700)
committerTim Otten <totten@civicrm.org>
Wed, 20 Jul 2022 08:41:15 +0000 (01:41 -0700)
CRM/Queue/Task.php

index da73d76379b6533e5d08913afd8fab9526fa286b..55817fae44cf3a7545e474ae6bf8bd8de26194c1 100644 (file)
@@ -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,
+      ]));
     }
   }