Skip to content

Commit f8aea29

Browse files
committed
refactor(scheduling): migrate health command scheduling to service provider
1 parent ebf748b commit f8aea29

2 files changed

Lines changed: 10 additions & 13 deletions

File tree

‎routes/console.php‎

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
11
<?php
22

3-
use Illuminate\Support\Facades\Schedule;
4-
use Spatie\Health\Commands\RunHealthChecksCommand;
5-
use Spatie\Health\Commands\ScheduleCheckHeartbeatCommand;
6-
73
/*
84
|--------------------------------------------------------------------------
95
| Console Routes
@@ -14,6 +10,3 @@
1410
| simple approach to interacting with each command's IO methods.
1511
|
1612
*/
17-
18-
Schedule::command(RunHealthChecksCommand::class)->everyMinute();
19-
Schedule::command(ScheduleCheckHeartbeatCommand::class)->everyMinute();

‎src/EclipseServiceProvider.php‎

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
use Filament\Support\Facades\FilamentAsset;
2626
use Filament\Tables\Columns\Column;
2727
use Illuminate\Auth\Events\Login;
28+
use Illuminate\Console\Scheduling\Schedule;
2829
use Illuminate\Database\Eloquent\Model;
2930
use Illuminate\Mail\Events\MessageSent;
3031
use Illuminate\Notifications\Channels\DatabaseChannel;
@@ -41,6 +42,8 @@
4142
use Spatie\Health\Checks\Checks\RedisCheck;
4243
use Spatie\Health\Checks\Checks\ScheduleCheck;
4344
use Spatie\Health\Checks\Checks\UsedDiskSpaceCheck;
45+
use Spatie\Health\Commands\RunHealthChecksCommand;
46+
use Spatie\Health\Commands\ScheduleCheckHeartbeatCommand;
4447
use Spatie\Health\Facades\Health;
4548
use Spatie\LaravelPackageTools\Package as SpatiePackage;
4649
use Spatie\SecurityAdvisoriesHealthCheck\SecurityAdvisoriesCheck;
@@ -74,10 +77,8 @@ public function configurePackage(SpatiePackage|Package $package): void
7477
->hasRoute('console');
7578
}
7679

77-
public function register(): self
80+
public function registeringPackage(): self
7881
{
79-
parent::register();
80-
8182
require_once __DIR__.'/Helpers/helpers.php';
8283

8384
Event::listen(Login::class, function ($event) {
@@ -109,10 +110,8 @@ public function register(): self
109110
return $this;
110111
}
111112

112-
public function boot(): void
113+
public function bootingPackage(): void
113114
{
114-
parent::boot();
115-
116115
// For unit tests...
117116
if (app()->runningUnitTests()) {
118117
// Set the correct user model in auth config
@@ -167,6 +166,11 @@ public function boot(): void
167166
return Route::post("/admin$path", $handle)
168167
->middleware(['web']);
169168
});
169+
170+
$this->callAfterResolving(Schedule::class, function (Schedule $schedule) {
171+
$schedule->command(RunHealthChecksCommand::class)->everyMinute();
172+
$schedule->command(ScheduleCheckHeartbeatCommand::class)->everyMinute();
173+
});
170174
}
171175

172176
private function isAdminRequest(): bool

0 commit comments

Comments
 (0)