From 912d0751110824a9ad828629d56aa942b41f9d73 Mon Sep 17 00:00:00 2001 From: Romain Thouvenin Date: Tue, 28 Nov 2017 15:58:50 +0100 Subject: [PATCH] CRM-21460 Add job execution hooks --- CRM/Core/JobManager.php | 3 +++ CRM/Utils/Hook.php | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+) diff --git a/CRM/Core/JobManager.php b/CRM/Core/JobManager.php index 6c3b1bec61..a40092ac29 100644 --- a/CRM/Core/JobManager.php +++ b/CRM/Core/JobManager.php @@ -141,12 +141,15 @@ class CRM_Core_JobManager { $params = $job->apiParams; } + CRM_Utils_Hook::preJob($job, $params); try { $result = civicrm_api($job->api_entity, $job->api_action, $params); } catch (Exception$e) { $this->logEntry('Error while executing ' . $job->name . ': ' . $e->getMessage()); + $result = $e; } + CRM_Utils_Hook::postJob($job, $params, $result); $this->logEntry('Finished execution of ' . $job->name . ' with result: ' . $this->_apiResultToMessage($result)); $this->currentJob = FALSE; } diff --git a/CRM/Utils/Hook.php b/CRM/Utils/Hook.php index 12e595fb5c..4a44349585 100644 --- a/CRM/Utils/Hook.php +++ b/CRM/Utils/Hook.php @@ -2396,4 +2396,36 @@ abstract class CRM_Utils_Hook { ); } + /** + * This hook is called before a scheduled job is executed + * + * @param CRM_Core_DAO_Job $job + * The job to be executed + * @param array $params + * The arguments to be given to the job + */ + public static function preJob($job, $params) { + return self::singleton()->invoke(array('job', 'params'), $job, $params, + self::$_nullObject, self::$_nullObject, self::$_nullObject, self::$_nullObject, + 'civicrm_preJob' + ); + } + + /** + * This hook is called after a scheduled job is executed + * + * @param CRM_Core_DAO_Job $job + * The job that was executed + * @param array $params + * The arguments given to the job + * @param array $result + * The result of the API call, or the thrown exception if any + */ + public static function postJob($job, $params, $result) { + return self::singleton()->invoke(array('job', 'params', 'result'), $job, $params, $result, + self::$_nullObject, self::$_nullObject, self::$_nullObject, + 'civicrm_postJob' + ); + } + } -- 2.25.1