You are here

function ultimate_cron_run_hook_cli in Ultimate Cron 7

Same name and namespace in other branches
  1. 8 ultimate_cron.module \ultimate_cron_run_hook_cli()
  2. 6 ultimate_cron.module \ultimate_cron_run_hook_cli()
1 call to ultimate_cron_run_hook_cli()
drush_ultimate_cron_cron_run in ./ultimate_cron.drush.inc
Run cron job(s)

File

./ultimate_cron.module, line 848
@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_cli($name, $hook) {

  // Run the job in background
  $result = NULL;
  $handle_prefix = variable_get('ultimate_cron_handle_prefix', ULTIMATE_CRON_HANDLE_PREFIX);
  $handle = $handle_prefix . $name;
  $process = new BackgroundProcess($handle);

  // Always run cron job as anonymous user
  $process->uid = 0;
  $hook['timestamp'] = time();
  if ($process
    ->lock()) {
    try {
      $process_obj = background_process_get_process($handle);
      $process->start = $process_obj->start;
      if (function_exists('background_process_update_status')) {
        background_process_update_status($handle, BACKGROUND_PROCESS_STATUS_RUNNING);
      }
      else {
        db_update('background_process')
          ->fields(array(
          'exec_status' => BACKGROUND_PROCESS_STATUS_RUNNING,
        ))
          ->condition('handle', $handle)
          ->execute();
      }
      $old_handle = background_process_current_handle();
      background_process_current_handle($handle);
      _ultimate_cron_run_hook($name, $hook);
      module_invoke_all('background_process_shutdown', $process);
      background_process_current_handle($old_handle);
      background_process_remove_process($handle, $process->start);
      return TRUE;
    } catch (Exception $e) {
      module_invoke_all('background_process_shutdown', $process, (string) $e);
      return NULL;
    }
  }
  return FALSE;
}