Skip to content

Commit 6ca105c

Browse files
committed
Merge branch 'schedule-work-command-improvements' into 8.x
2 parents 0a59b01 + bbddba2 commit 6ca105c

File tree

1 file changed

+31
-3
lines changed

1 file changed

+31
-3
lines changed

src/Illuminate/Console/Scheduling/ScheduleWorkCommand.php

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
use Illuminate\Console\Command;
66
use Illuminate\Support\Carbon;
7+
use Illuminate\Support\Str;
8+
use Symfony\Component\Process\Process;
79

810
class ScheduleWorkCommand extends Command
911
{
@@ -30,12 +32,38 @@ public function handle()
3032
{
3133
$this->info('Schedule worker started successfully.');
3234

35+
[$lastExecutionStartedAt, $keyOfLastExecutionWithOutput, $executions] = [null, null, []];
36+
3337
while (true) {
34-
if (Carbon::now()->second === 0) {
35-
$this->call('schedule:run');
38+
usleep(100 * 1000);
39+
40+
if (Carbon::now()->second === 0 &&
41+
! Carbon::now()->startOfMinute()->equalTo($lastExecutionStartedAt)) {
42+
$executions[] = $execution = new Process([PHP_BINARY, 'artisan', 'schedule:run']);
43+
44+
$execution->start();
45+
46+
$lastExecutionStartedAt = Carbon::now()->startOfMinute();
3647
}
3748

38-
sleep(1);
49+
foreach ($executions as $key => $execution) {
50+
$output = trim($execution->getIncrementalOutput()).
51+
trim($execution->getIncrementalErrorOutput());
52+
53+
if (! empty($output)) {
54+
if ($key !== $keyOfLastExecutionWithOutput) {
55+
$this->info(PHP_EOL.'Execution #'.($key + 1).' output:');
56+
57+
$keyOfLastExecutionWithOutput = $key;
58+
}
59+
60+
$this->output->writeln($output);
61+
}
62+
63+
if (! $execution->isRunning()) {
64+
unset($executions[$key]);
65+
}
66+
}
3967
}
4068
}
4169
}

0 commit comments

Comments
 (0)