Beispiel #1
0
 /**
  * Runs all of the tasks (after checking their time, of course...)
  *
  * @param string $alias
  * @return mixed
  */
 public function run($alias = null)
 {
     // Has the system been disabled?
     if (Settings::get('is_disabled', 'cron') == 'y') {
         return CLI::error('The cron system has been disabled. No tasks were run.');
     }
     $force_run = false;
     // Run one task or all?
     if (!empty($alias)) {
         $tasks = \Myth\Cron\CronManager::task($alias);
         if (is_null($tasks)) {
             return CLI::error("Unable to find the task: '{$alias}'.");
         }
         $tasks = [$alias => $tasks];
         $force_run = true;
     } else {
         $tasks = \Myth\Cron\CronManager::tasks();
     }
     if (empty($tasks)) {
         return CLI::write("There are no tasks to run at this time.");
     }
     // We need to be able to check against suspended tasks.
     $suspended = Settings::get('suspended_tasks', 'cron');
     if (!is_array($suspended)) {
         $suspended = array($suspended);
     }
     // Loop over all of our tasks, checking them against the
     // suspended tasks to see if they're okay to run.
     // Collect the output of the actions so that we can make
     // it available to the event (for sending emails and the like)
     $output = '';
     echo CLI::write('Starting Tasks...');
     foreach ($tasks as $alias => $task) {
         if (in_array($alias, $suspended)) {
             echo CLI::write("\t[Suspended] {$alias} will not run until resumed.", 'yellow');
             $output .= "[Suspended] {$alias} will not run until resumed.";
             continue;
         }
         echo CLI::write("\tRunning task: {$alias}...");
         $output .= \Myth\Cron\CronManager::run($alias, $force_run);
     }
     // Give other people a chance to respond.
     echo CLI::write('Done. Firing the event so others can play too...');
     Events::trigger('afterCron', [$output]);
     // And we're out of here boys and girls!
     echo CLI::write('Done');
 }
Beispiel #2
0
 public function testRunActuallyRunsSingleTask()
 {
     CronManager::schedule('task1', '5 minutes', function () {
         return true;
     });
     CronManager::schedule('task2', '5 minutes', function () {
         return true;
     });
     $current_time = strtotime('10:45:05');
     $result = CronManager::run('task1', false, $current_time);
     $this->assertTrue(strpos($result, 'task1') !== false);
     $this->assertTrue(strpos($result, 'Done') !== false);
     $this->assertTrue(strpos($result, 'task2') === false);
 }