CronRun.php 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. <?php
  2. namespace app\console\Commands;
  3. use app\framework\Cron\Cron;
  4. use app\framework\Log\CronLog;
  5. use Liebig\Cron\RunCommand;
  6. class CronRun extends RunCommand
  7. {
  8. /**
  9. * Execute the console command.
  10. *
  11. * @return void
  12. */
  13. public function fire() {
  14. // Fire event before the Cron jobs will be executed
  15. \Event::dispatch('cron.collectJobs');
  16. $report = Cron::run();
  17. if($report['inTime'] === -1) {
  18. $inTime = -1;
  19. } else if ($report['inTime']) {
  20. $inTime = 'true';
  21. } else {
  22. $inTime = 'false';
  23. }
  24. // Get Laravel version
  25. $laravel = app();
  26. $version = $laravel::VERSION;
  27. if ($version < '5.2') {
  28. // Create table for old Laravel versions.
  29. $table = $this->getHelperSet()->get('table');
  30. $table->setHeaders(array('Run date', 'In time', 'Run time', 'Errors', 'Jobs'));
  31. $table->addRow(array($report['rundate'], $inTime, round($report['runtime'], 4), $report['errors'], count($report['crons'])));
  32. } else {
  33. // Create table for new Laravel versions.
  34. $table = new \Symfony\Component\Console\Helper\Table($this->getOutput());
  35. $table
  36. ->setHeaders(array('Run date', 'In time', 'Run time', 'Errors', 'Jobs'))
  37. ->setRows(array(array($report['rundate'], $inTime, round($report['runtime'], 4), $report['errors'], count($report['crons']))));
  38. }
  39. // Output table.
  40. $table->render($this->getOutput());
  41. }
  42. }