diff --git a/src/Illuminate/Console/Scheduling/ScheduleWorkCommand.php b/src/Illuminate/Console/Scheduling/ScheduleWorkCommand.php index d1f33ab29f8f..10776d093c50 100644 --- a/src/Illuminate/Console/Scheduling/ScheduleWorkCommand.php +++ b/src/Illuminate/Console/Scheduling/ScheduleWorkCommand.php @@ -4,6 +4,8 @@ use Illuminate\Console\Command; use Illuminate\Support\Carbon; +use Illuminate\Support\Str; +use Symfony\Component\Process\Process; class ScheduleWorkCommand extends Command { @@ -30,12 +32,47 @@ public function handle() { $this->info('Schedule worker started successfully.'); + $lastExecutionStartedAt = null; + + $keyOfLastExecutionWithOutput = null; + + $executions = []; + while (true) { - if (Carbon::now()->second === 0) { - $this->call('schedule:run'); + if (Carbon::now()->second === 0 && ! Carbon::now()->startOfMinute()->equalTo($lastExecutionStartedAt)) { + $execution = new Process([PHP_BINARY, 'artisan', 'schedule:run']); + $execution->start(); + $executions[] = $execution; + $lastExecutionStartedAt = Carbon::now()->startOfMinute(); } - sleep(1); + foreach ($executions as $key => $execution) { + $incrementalOutput = trim($execution->getIncrementalOutput()); + + if (Str::length($incrementalOutput) > 0) { + if ($key !== $keyOfLastExecutionWithOutput) { + $this->info(PHP_EOL.'Execution #'.($key + 1).' output:'); + $keyOfLastExecutionWithOutput = $key; + } + + $this->warn($incrementalOutput); + } + + $incrementalErrorOutput = trim($execution->getIncrementalErrorOutput()); + + if (Str::length($incrementalErrorOutput) > 0) { + if ($key !== $keyOfLastExecutionWithOutput) { + $this->info(PHP_EOL.'Execution #'.($key + 1).' output:'); + $keyOfLastExecutionWithOutput = $key; + } + + $this->error(trim($incrementalErrorOutput)); + } + + if (! $execution->isRunning()) { + unset($executions[$key]); + } + } } } }