You are here

function _ultimate_cron_run_hook in Ultimate Cron 6

Same name and namespace in other branches
  1. 8 ultimate_cron.module \_ultimate_cron_run_hook()
  2. 7 ultimate_cron.module \_ultimate_cron_run_hook()

This is the function that is launched into a background process. It runs the cron job and does housekeeping, pre/post execute hooks, etc.

Parameters

$module: Module containing function.

$name: Function to call.

Return value

boolean TRUE on success, FALSE on failure.

1 call to _ultimate_cron_run_hook()
ultimate_cron_run_hook_cli in ./ultimate_cron.module
1 string reference to '_ultimate_cron_run_hook'
ultimate_cron_run_hook in ./ultimate_cron.module
Run a cron hook. Launches the cron job in a background process

File

./ultimate_cron.module, line 865
@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_run_hook($name, $hook) {
  @set_time_limit(variable_get('ultimate_cron_max_execution_time', ULTIMATE_CRON_MAX_EXECUTION_TIME));

  // Load current process
  $process = background_process_get_process(background_process_current_handle());
  $record =& ultimate_cron_static('ultimate_cron_record', FALSE);
  $record = TRUE;
  ultimate_cron_record_log(NULL, TRUE);

  // Load log if not present
  if (!isset($hook['log'])) {
    $hook['log'] = ultimate_cron_get_log($name);
  }
  $time = time();
  if (empty($hook['skip_catch_up']) && !ultimate_cron_hook_should_run($hook)) {

    // Hook started too late!
    watchdog('ultimate_cron', '%function skipped. Invoked at %invoke, but did not start until %start', array(
      '%function' => $name,
      '%invoke' => format_date($hook['timestamp'], 'custom', 'Y-m-d H:i:s'),
      '%start' => format_date($time, 'custom', 'Y-m-d H:i:s'),
    ), WATCHDOG_ERROR);
    ultimate_cron_background_process_shutdown($process, NULL);
    return FALSE;
  }

  // Let other modules do stuff before execution, if they need to.
  module_invoke_all('cron_pre_execute', $name, $hook);
  module_invoke_all('cron_pre_execute_' . $name, $hook);
  if (!empty($hook['file'])) {
    include_once $hook['file'];
  }
  $callback = $hook['callback'];
  ultimate_cron_set_current_hook($hook);
  if (is_callable($callback)) {
    call_user_func($callback);
  }
  else {
    module_invoke($hook['module'], 'cronapi', 'execute', $name, $hook);
  }
  ultimate_cron_background_process_shutdown($process, NULL);

  // Let other modules do stuff before execution, if they need to.
  module_invoke_all('cron_post_execute', $name, $hook);
  module_invoke_all('cron_post_execute_' . $name, $hook);
  return TRUE;
}