public function testLog() { $message = 'php artisan'; $this->output->shouldReceive('writeln')->once()->with($message); $debugger = new Debugger($this->optionReader, $this->output); $debugger->log($message); }
/** * Get all commands that are due to be run * * @param Debugger $debugger * * @throws \InvalidArgumentException * @return \Indatus\Dispatcher\Queue */ public function getQueue(Debugger $debugger) { /** @var \Indatus\Dispatcher\Queue $queue */ $queue = App::make('Indatus\\Dispatcher\\Queue'); /** @var \Indatus\Dispatcher\Scheduling\ScheduledCommandInterface $command */ foreach ($this->getScheduledCommands() as $command) { /** @var \Indatus\Dispatcher\Scheduling\Schedulable $scheduler */ $scheduler = App::make('Indatus\\Dispatcher\\Scheduling\\Schedulable'); //could be multiple schedules based on arguments $schedules = $command->schedule($scheduler); if (!is_array($schedules)) { $schedules = array($schedules); } $willBeRun = false; foreach ($schedules as $schedule) { if ($schedule instanceof Schedulable === false) { throw new \InvalidArgumentException('Schedule for "' . $command->getName() . '" is not an instance of Schedulable'); } if ($this->isDue($schedule)) { /** @var \Indatus\Dispatcher\QueueItem $queueItem */ $queueItem = App::make('Indatus\\Dispatcher\\QueueItem'); $queueItem->setCommand($command); $queueItem->setScheduler($schedule); if ($queue->add($queueItem)) { $willBeRun = true; } } } //it didn't run, so record that it didn't run if ($willBeRun === false) { $debugger->commandNotRun($command, 'No schedules were due'); } } return $queue; }
/** * Run all commands that are due to be run */ public function runDue(Debugger $debugger) { $debugger->log('Running commands...'); /** @var \Indatus\Dispatcher\BackgroundProcessRunner $backgroundProcessRunner */ $backgroundProcessRunner = App::make('Indatus\\Dispatcher\\BackgroundProcessRunner'); /** @var \Indatus\Dispatcher\Queue $queue */ $queue = $this->scheduleService->getQueue($debugger); foreach ($queue->flush() as $queueItem) { /** @var \Indatus\Dispatcher\Scheduling\ScheduledCommandInterface $command */ $command = $queueItem->getCommand(); //determine if the command is enabled if ($command->isEnabled()) { if ($this->runnableInCurrentMaintenanceSetting($command)) { if ($this->runnableInEnvironment($command)) { $scheduler = $queueItem->getScheduler(); $backgroundProcessRunner->run($command, $scheduler->getArguments(), $scheduler->getOptions(), $debugger); } else { $debugger->commandNotRun($command, 'Command is not configured to run in ' . App::environment()); } } else { $debugger->commandNotRun($command, 'Command is not configured to run while application is in maintenance mode'); } } else { $debugger->commandNotRun($command, 'Command is disabled'); } } }