function ultimate_cron_background_process_shutdown in Ultimate Cron 6
Same name and namespace in other branches
- 8 ultimate_cron.module \ultimate_cron_background_process_shutdown()
- 7.2 ultimate_cron.background_process.inc \ultimate_cron_background_process_shutdown()
- 7 ultimate_cron.module \ultimate_cron_background_process_shutdown()
Implements hook_background_process_shutdown().
Shutdown handler for cronjobs.
1 call to ultimate_cron_background_process_shutdown()
- _ultimate_cron_run_hook in ./
ultimate_cron.module - This is the function that is launched into a background process. It runs the cron job and does housekeeping, pre/post execute hooks, etc.
File
- ./
ultimate_cron.module, line 570 - @todo Add filter on overview page. @todo Add log view (with graph). @todo Make proper markup for overview page. @todo Refactor drush stuff, too many intimate relations with Background Process @todo Refactor Cron % offset stuff. Too mixed up and…
Code
function ultimate_cron_background_process_shutdown($process, $shutdown_msg = NULL) {
$args = func_get_args();
$record = ultimate_cron_static('ultimate_cron_record', FALSE);
$handle_prefix = variable_get('ultimate_cron_handle_prefix', ULTIMATE_CRON_HANDLE_PREFIX);
$name = preg_replace('/^' . $handle_prefix . '/', '', $process->handle);
if (!empty($name) && $name != $process->handle) {
static $has_run = array();
if (!empty($has_run[$name])) {
return;
}
$has_run[$name] = TRUE;
// Record end time
$end = microtime(TRUE);
if ($record) {
// Get drupal messages
$messages = drupal_get_messages(NULL, TRUE);
$messages['status'] = empty($messages['status']) ? array() : $messages['status'];
$messages['warning'] = empty($messages['warning']) ? array() : $messages['warning'];
$messages['error'] = empty($messages['error']) ? array() : $messages['error'];
foreach ($messages['status'] as $message) {
ultimate_cron_record_log($message);
}
foreach ($messages['warning'] as $message) {
ultimate_cron_record_log($message, FALSE, WATCHDOG_WARNING);
}
foreach ($messages['error'] as $message) {
ultimate_cron_record_log($message, FALSE, WATCHDOG_ERROR);
}
// Get error messages
$error = error_get_last();
if ($error) {
$message = $error['message'] . ' (line ' . $error['line'] . ' of ' . $error['file'] . ').' . "\n";
$severity = WATCHDOG_INFO;
if ($error['type'] && (E_NOTICE || E_USER_NOTICE || E_USER_WARNING)) {
$severity = WATCHDOG_NOTICE;
}
if ($error['type'] && (E_WARNING || E_CORE_WARNING || E_USER_WARNING)) {
$severity = WATCHDOG_WARNING;
}
if ($error['type'] && (E_ERROR || E_CORE_ERROR || E_USER_ERROR || E_RECOVERABLE_ERROR)) {
$severity = WATCHDOG_ERROR;
}
ultimate_cron_record_log($message, FALSE, $severity);
}
}
if ($shutdown_msg) {
ultimate_cron_record_log($shutdown_msg, FALSE, WATCHDOG_ERROR);
}
$log = ultimate_cron_static('ultimate_cron_record_log', array(
'msg' => '',
'severity' => -1,
));
$severity = $log['severity'];
$msg = $log['msg'];
$result = $severity < 0 || $severity >= WATCHDOG_INFO ? 1 : 0;
// log results here ...
$object = (object) array(
'name' => $name,
'start_stamp' => $process->start,
'end_stamp' => $end,
'exec_status' => $result,
'service_host' => $process->service_host,
'severity' => $severity,
'msg' => trim($msg),
);
drupal_write_record('ultimate_cron_log', $object);
}
}