Skip to content

Commit 0b1bf46

Browse files
[5.x] Improves console output and fixes Carbon v3 support (#1387)
* Deprecates Laravel 8, PHP 7.3 and PHP 7.4 * Improves output of `clear` command * Improves output of `clear:metrics` command * Improves output of `continue` command * Improves output of `supervisor:continue` command * Improves output of `forget:failed` command * Improves output of `horizon` command * Improves output of `install` command * Improves output of `list` command * Improves output of `timeout` command * Improves output of `supervisors` command * Improves output of `supervisor` command * Improves output of `status` command * Improves output of `snapshot` command * Improves output of `supervisor:pause` command * Improves output of `pause` command * Improves output of `terminate` command * Improves output of `purge` command * Fixes adding seconds to process `terminatedAt` * Update TimeoutCommand.php * Update PurgeCommand.php --------- Co-authored-by: Taylor Otwell <taylor@laravel.com>
1 parent e62a24a commit 0b1bf46

20 files changed

+113
-83
lines changed

.github/workflows/tests.yml

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -23,21 +23,9 @@ jobs:
2323
strategy:
2424
fail-fast: true
2525
matrix:
26-
php: [7.3, 7.4, '8.0', 8.1, 8.2, 8.3]
27-
laravel: [8, 9, 10, 11]
26+
php: ['8.0', 8.1, 8.2, 8.3]
27+
laravel: [9, 10, 11]
2828
exclude:
29-
- php: 7.3
30-
laravel: 9
31-
- php: 7.3
32-
laravel: 10
33-
- php: 7.3
34-
laravel: 11
35-
- php: 7.4
36-
laravel: 9
37-
- php: 7.4
38-
laravel: 10
39-
- php: 7.4
40-
laravel: 11
4129
- php: '8.0'
4230
laravel: 10
4331
- php: '8.0'

composer.json

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,21 +10,21 @@
1010
}
1111
],
1212
"require": {
13-
"php": "^7.3|^8.0",
13+
"php": "^8.0",
1414
"ext-json": "*",
1515
"ext-pcntl": "*",
1616
"ext-posix": "*",
17-
"illuminate/contracts": "^8.17|^9.0|^10.0|^11.0",
18-
"illuminate/queue": "^8.17|^9.0|^10.0|^11.0",
19-
"illuminate/support": "^8.17|^9.0|^10.0|^11.0",
17+
"illuminate/contracts": "^9.21|^10.0|^11.0",
18+
"illuminate/queue": "^9.21|^10.0|^11.0",
19+
"illuminate/support": "^9.21|^10.0|^11.0",
2020
"nesbot/carbon": "^2.17|^3.0",
2121
"ramsey/uuid": "^4.0",
22-
"symfony/process": "^5.0|^6.0|^7.0",
23-
"symfony/error-handler": "^5.0|^6.0|^7.0"
22+
"symfony/process": "^6.0|^7.0",
23+
"symfony/error-handler": "^6.0|^7.0"
2424
},
2525
"require-dev": {
2626
"mockery/mockery": "^1.0",
27-
"orchestra/testbench": "^6.0|^7.0|^8.0|^9.0",
27+
"orchestra/testbench": "^7.0|^8.0|^9.0",
2828
"phpstan/phpstan": "^1.10",
2929
"phpunit/phpunit": "^9.0|^10.4",
3030
"predis/predis": "^1.1|^2.0"

src/Console/ClearCommand.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public function handle(JobRepository $jobRepository, QueueManager $manager)
4141
}
4242

4343
if (! method_exists(RedisQueue::class, 'clear')) {
44-
$this->line('<error>Clearing queues is not supported on this version of Laravel</error>');
44+
$this->components->error('Clearing queues is not supported on this version of Laravel.');
4545

4646
return 1;
4747
}
@@ -54,7 +54,7 @@ public function handle(JobRepository $jobRepository, QueueManager $manager)
5454

5555
$count = $manager->connection($connection)->clear($queue);
5656

57-
$this->line('<info>Cleared '.$count.' jobs from the ['.$queue.'] queue</info> ');
57+
$this->components->info('Cleared '.$count.' jobs from the ['.$queue.'] queue.');
5858

5959
return 0;
6060
}

src/Console/ClearMetricsCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,6 @@ public function handle(MetricsRepository $metrics)
3131
{
3232
$metrics->clear();
3333

34-
$this->info('Metrics cleared successfully.');
34+
$this->components->info('Metrics cleared successfully.');
3535
}
3636
}

src/Console/ContinueCommand.php

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,19 @@ public function handle(MasterSupervisorRepository $masters)
3636
return Str::startsWith($master->name, MasterSupervisor::basename());
3737
})->all();
3838

39-
foreach (Arr::pluck($masters, 'pid') as $processId) {
40-
$this->info("Sending CONT Signal To Process: {$processId}");
39+
collect(Arr::pluck($masters, 'pid'))
40+
->whenNotEmpty(fn () => $this->components->info('Sending CONT signal to processes.'))
41+
->whenEmpty(fn () => $this->components->info('No processes to continue.'))
42+
->each(function ($processId) {
43+
$result = true;
4144

42-
if (! posix_kill($processId, SIGCONT)) {
43-
$this->error("Failed to kill process: {$processId} (".posix_strerror(posix_get_last_error()).')');
44-
}
45-
}
45+
$this->components->task("Process: $processId", function () use ($processId, &$result) {
46+
return $result = posix_kill($processId, SIGCONT);
47+
});
48+
49+
if (! $result) {
50+
$this->components->error("Failed to kill process: {$processId} (".posix_strerror(posix_get_last_error()).')');
51+
}
52+
})->whenNotEmpty(fn () => $this->output->writeln(''));
4653
}
4754
}

src/Console/ContinueSupervisorCommand.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,15 +38,15 @@ public function handle(SupervisorRepository $supervisors)
3838
}))->pid;
3939

4040
if (is_null($processId)) {
41-
$this->error('Failed to find a supervisor with this name');
41+
$this->components->error('Failed to find a supervisor with this name');
4242

4343
return 1;
4444
}
4545

46-
$this->info("Sending CONT Signal To Process: {$processId}");
46+
$this->components->info("Sending CONT signal to process: {$processId}");
4747

4848
if (! posix_kill($processId, SIGCONT)) {
49-
$this->error("Failed to send CONT signal to process: {$processId} (".posix_strerror(posix_get_last_error()).')');
49+
$this->components->error("Failed to send CONT signal to process: {$processId} (".posix_strerror(posix_get_last_error()).')');
5050
}
5151
}
5252
}

src/Console/ForgetFailedCommand.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@ public function handle(JobRepository $repository)
3131
$repository->deleteFailed($this->argument('id'));
3232

3333
if ($this->laravel['queue.failer']->forget($this->argument('id'))) {
34-
$this->info('Failed job deleted successfully!');
34+
$this->components->info('Failed job deleted successfully!');
3535
} else {
36-
$this->error('No failed job matches the given ID.');
36+
$this->components->error('No failed job matches the given ID.');
3737

3838
return 1;
3939
}

src/Console/HorizonCommand.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class HorizonCommand extends Command
3232
public function handle(MasterSupervisorRepository $masters)
3333
{
3434
if ($masters->find(MasterSupervisor::name())) {
35-
return $this->comment('A master supervisor is already running on this machine.');
35+
return $this->components->warn('A master supervisor is already running on this machine.');
3636
}
3737

3838
$environment = $this->option('environment') ?? config('horizon.env') ?? config('app.env');
@@ -43,12 +43,14 @@ public function handle(MasterSupervisorRepository $masters)
4343

4444
ProvisioningPlan::get(MasterSupervisor::name())->deploy($environment);
4545

46-
$this->info('Horizon started successfully.');
46+
$this->components->info('Horizon started successfully.');
4747

4848
pcntl_async_signals(true);
4949

5050
pcntl_signal(SIGINT, function () use ($master) {
51-
$this->line('Shutting down...');
51+
$this->output->writeln('');
52+
53+
$this->components->info('Shutting down.');
5254

5355
return $master->terminate();
5456
});

src/Console/InstallCommand.php

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,18 +29,17 @@ class InstallCommand extends Command
2929
*/
3030
public function handle()
3131
{
32-
$this->comment('Publishing Horizon Service Provider...');
33-
$this->callSilent('vendor:publish', ['--tag' => 'horizon-provider']);
32+
$this->components->info('Installing Horizon resources.');
3433

35-
$this->comment('Publishing Horizon Assets...');
36-
$this->callSilent('vendor:publish', ['--tag' => 'horizon-assets']);
37-
38-
$this->comment('Publishing Horizon Configuration...');
39-
$this->callSilent('vendor:publish', ['--tag' => 'horizon-config']);
34+
collect([
35+
'Assets' => fn () => $this->callSilent('vendor:publish', ['--tag' => 'horizon-assets']) == 0,
36+
'Service Provider' => fn () => $this->callSilent('vendor:publish', ['--tag' => 'horizon-provider']) == 0,
37+
'Configuration' => fn () => $this->callSilent('vendor:publish', ['--tag' => 'horizon-config']) == 0,
38+
])->each(fn ($task, $description) => $this->components->task($description, $task));
4039

4140
$this->registerHorizonServiceProvider();
4241

43-
$this->info('Horizon scaffolding installed successfully.');
42+
$this->components->info('Horizon scaffolding installed successfully.');
4443
}
4544

4645
/**

src/Console/ListCommand.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,11 @@ public function handle(MasterSupervisorRepository $masters)
3232
$masters = $masters->all();
3333

3434
if (empty($masters)) {
35-
return $this->info('No machines are running.');
35+
return $this->components->info('No machines are running.');
3636
}
3737

38+
$this->output->writeln('');
39+
3840
$this->table([
3941
'Name', 'PID', 'Supervisors', 'Status',
4042
], collect($masters)->map(function ($master) {
@@ -47,5 +49,7 @@ public function handle(MasterSupervisorRepository $masters)
4749
$master->status,
4850
];
4951
})->all());
52+
53+
$this->output->writeln('');
5054
}
5155
}

0 commit comments

Comments
 (0)