Skip to content

Commit

Permalink
CRM-21460 Add job execution hooks
Browse files Browse the repository at this point in the history
  • Loading branch information
rthouvenin committed Nov 28, 2017
1 parent 4103cb7 commit 912d075
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
3 changes: 3 additions & 0 deletions CRM/Core/JobManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -141,12 +141,15 @@ public function executeJob($job) {
$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;
}
Expand Down
32 changes: 32 additions & 0 deletions CRM/Utils/Hook.php
Original file line number Diff line number Diff line change
Expand Up @@ -2396,4 +2396,36 @@ public static function alterEntityRefParams(&$params, $formName) {
);
}

/**
* 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'
);
}

}

0 comments on commit 912d075

Please sign in to comment.