function drush_ultimate_cron_cron_list in Ultimate Cron 8.2
Same name and namespace in other branches
- 8 ultimate_cron.drush.inc \drush_ultimate_cron_cron_list()
- 6 ultimate_cron.drush.inc \drush_ultimate_cron_cron_list()
- 7.2 ultimate_cron.drush.inc \drush_ultimate_cron_cron_list()
- 7 ultimate_cron.drush.inc \drush_ultimate_cron_cron_list()
List cron jobs.
File
- ./
ultimate_cron.drush.inc, line 143 - Drush commands for Ultimate Cron!
Code
function drush_ultimate_cron_cron_list() {
$modules = drush_get_option('module');
$enabled = drush_get_option('enabled');
$disabled = drush_get_option('disabled');
$behind = drush_get_option('behind');
$extended = drush_get_option('extended');
$statuses = drush_get_option('status');
$scheduled = drush_get_option('scheduled');
$showname = drush_get_option('name');
$modules = $modules ? explode(',', $modules) : array();
$statuses = $statuses ? explode(',', $statuses) : array();
$title = $showname ? dt('Name') : dt('Title');
$table = array();
$table[] = array(
'',
dt('ID'),
dt('Module'),
$title,
dt('Scheduled'),
dt('Started'),
dt('Duration'),
dt('Status'),
);
$print_legend = FALSE;
/** @var \Drupal\ultimate_cron\Entity\CronJob $job */
foreach (CronJob::loadMultiple() as $name => $job) {
if ($modules && !in_array($job
->getModule(), $modules)) {
continue;
}
if ($enabled && FALSE === $job
->status()) {
continue;
}
if ($disabled && TRUE === $job
->status()) {
continue;
}
if ($scheduled && !$job
->isScheduled()) {
continue;
}
$legend = '';
if (FALSE === $job
->status()) {
$legend .= 'D';
$print_legend = TRUE;
}
$lock_id = $job
->isLocked();
$log_entry = $job
->loadLogEntry($lock_id);
if ($time = $job
->isBehindSchedule()) {
$legend .= 'B';
$print_legend = TRUE;
}
if ($behind && !$time) {
continue;
}
if ($lock_id && $log_entry->lid == $lock_id) {
$legend .= 'R';
list(, $status) = $job
->getPlugin('launcher')
->formatRunning($job);
$print_legend = TRUE;
}
elseif ($log_entry->start_time && !$log_entry->end_time) {
list(, $status) = $job
->getPlugin('launcher')
->formatUnfinished($job);
}
else {
list(, $status) = $log_entry
->formatSeverity();
}
if ($statuses && !in_array($status, $statuses)) {
continue;
}
$progress = $lock_id ? $job
->formatProgress() : '';
$table[$name][] = $legend;
$table[$name][] = $job
->id();
$table[$name][] = $job
->getModuleName();
$table[$name][] = $showname ? $job
->id() : $job
->getTitle();
$table[$name][] = $job
->getPlugin('scheduler')
->formatLabel($job);
$table[$name][] = $log_entry
->formatStartTime();
$table[$name][] = $log_entry
->formatDuration() . ' ' . $progress;
$table[$name][] = $status;
if ($extended) {
$table['extended:' . $name][] = '';
$table['extended:' . $name][] = '';
$table['extended:' . $name][] = $job
->id();
$table['extended:' . $name][] = $job
->getPlugin('scheduler')
->formatLabelVerbose($job);
$table['extended:' . $name][] = $log_entry->init_message;
$table['extended:' . $name][] = $log_entry->message;
}
}
drush_print_table($table);
if ($print_legend) {
drush_print("\n" . dt('Legend: D = Disabled, R = Running, B = Behind schedule'));
}
}