You are here

function drush_ultimate_cron_cron_logs in Ultimate Cron 7.2

Same name and namespace in other branches
  1. 8.2 ultimate_cron.drush.inc \drush_ultimate_cron_cron_logs()

List cron jobs.

File

./ultimate_cron.drush.inc, line 290
Drush commands for Ultimate Cron!

Code

function drush_ultimate_cron_cron_logs($name = NULL) {
  if (!$name) {
    return drush_set_error(dt('No job specified?'));
  }
  $job = _ultimate_cron_job_load($name);
  if (!$job) {
    return drush_set_error(dt('@name not found', array(
      '@name' => $name,
    )));
  }
  $compact = drush_get_option('compact');
  $limit = drush_get_option('limit');
  $limit = $limit ? $limit : 10;
  $table = array();
  $table[] = array(
    '',
    dt('Started'),
    dt('Duration'),
    dt('User'),
    dt('Initial message'),
    dt('Message'),
    dt('Status'),
  );
  $lock_id = $job
    ->isLocked();
  $log_entries = $job
    ->getLogEntries(ULTIMATE_CRON_LOG_TYPE_ALL, $limit);
  $progress = $job
    ->getProgress();
  foreach ($log_entries as $log_entry) {
    $progress = '';
    if ($log_entry->lid && $lock_id && $log_entry->lid === $lock_id) {
      $progress = $job
        ->getProgress();
      $progress = is_numeric($progress) ? sprintf(" (%d%%)", round($progress * 100)) : '';
    }
    $legend = '';
    if ($lock_id && $log_entry->lid == $lock_id) {
      $legend .= 'R';
      list($null, $status) = $job
        ->getPlugin('launcher')
        ->formatRunning($job);
    }
    elseif ($log_entry->start_time && !$log_entry->end_time) {
      list($null, $status) = $job
        ->getPlugin('launcher')
        ->formatUnfinished($job);
    }
    else {
      list($null, $status) = $log_entry
        ->formatSeverity();
    }
    $table[$log_entry->lid][] = $legend;
    $table[$log_entry->lid][] = $log_entry
      ->formatStartTime();
    $table[$log_entry->lid][] = $log_entry
      ->formatDuration() . $progress;
    $table[$log_entry->lid][] = $log_entry
      ->formatUser();
    if ($compact) {
      $table[$log_entry->lid][] = trim(reset(explode("\n", $log_entry->init_message)), "\n");
      $table[$log_entry->lid][] = trim(reset(explode("\n", $log_entry->message)), "\n");
    }
    else {
      $table[$log_entry->lid][] = trim($log_entry->init_message, "\n");
      $table[$log_entry->lid][] = trim($log_entry->message, "\n");
    }
    $table[$log_entry->lid][] = $status;
  }
  drush_print_table($table);
}