コード例 #1
0
ファイル: Cron.php プロジェクト: leloulight/Sprint
 /**
  * Lists one or more tasks with their scheduled run times.
  *
  * @param null $task
  * @return mixed
  */
 public function show($task = null)
 {
     if (empty($task)) {
         return $this->listTaskNames();
     }
     if (trim(strtolower($task)) == 'all') {
         $tasks = \Myth\Cron\CronManager::listAll();
     } else {
         $tasks = \Myth\Cron\CronManager::task($task);
     }
     if (!is_array($tasks)) {
         $tasks = [$task => ['next_run' => $tasks->nextRunDate(), 'prev_run' => $tasks->previousRunDate()]];
     }
     if (!count($tasks)) {
         return CLI::found('No tasks found.', 'red');
     }
     $suspended = Settings::get('suspended_tasks', 'cron');
     if (empty($suspended)) {
         $suspended = [];
     }
     /*
      * Headers
      */
     echo CLI::write("Task\t\t\t\tNext Run\t\tPrevious Run");
     echo CLI::write(str_repeat('-', 80));
     foreach ($tasks as $alias => $task) {
         // Suspended?
         $color = 'yellow';
         $extra = '';
         if (in_array($alias, $suspended)) {
             $color = 'blue';
             $extra = "\t[Suspended]";
         }
         // Alias can only be 24 chars long.
         $alias = strlen($alias) >= 32 ? substr($alias, 0, 28) . '... ' : $alias . str_repeat(" ", 32 - strlen($alias));
         $next = date('D Y-m-d H:i', $task['next_run']);
         $prev = date('D Y-m-d H:i', $task['prev_run']);
         echo CLI::write("{$alias}{$next}\t{$prev}{$extra}", $color);
     }
 }