Skip to content

Commit

Permalink
Laravel pulse and spatie-health initial integration (#648)
Browse files Browse the repository at this point in the history
* add pulse and health check

* chore: Add pulse and health check

* feat: Add test for general health route
  • Loading branch information
vincentauger authored Jun 3, 2024
1 parent 6e63bbb commit 7ffd300
Show file tree
Hide file tree
Showing 16 changed files with 1,965 additions and 5 deletions.
99 changes: 99 additions & 0 deletions .phpstorm.meta.php

Large diffs are not rendered by default.

853 changes: 853 additions & 0 deletions _ide_helper.php

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions app/Console/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Illuminate\Console\Scheduling\Schedule;
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;
use Spatie\Health\Commands\RunHealthChecksCommand;

class Kernel extends ConsoleKernel
{
Expand All @@ -22,6 +23,10 @@ protected function schedule(Schedule $schedule)
// backup the database
$schedule->command('backup:clean')->daily()->at('01:00');
$schedule->command('backup:run --only-db')->daily()->at('02:00');

// health checks
$schedule->command(RunHealthChecksCommand::class)->everyMinute();

}

/**
Expand Down
28 changes: 27 additions & 1 deletion app/Providers/AppServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,18 @@
namespace App\Providers;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\App;
use Illuminate\Support\Facades\Gate;
use Illuminate\Support\Facades\Schema;
use Illuminate\Support\ServiceProvider;
use Spatie\Health\Checks\Checks\CacheCheck;
use Spatie\Health\Checks\Checks\DatabaseCheck;
use Spatie\Health\Checks\Checks\DebugModeCheck;
use Spatie\Health\Checks\Checks\HorizonCheck;
use Spatie\Health\Checks\Checks\PingCheck;
use Spatie\Health\Checks\Checks\RedisCheck;
use Spatie\Health\Checks\Checks\UsedDiskSpaceCheck;
use Spatie\Health\Facades\Health;

class AppServiceProvider extends ServiceProvider
{
Expand All @@ -26,11 +36,27 @@ public function register()
public function boot()
{
// prevent lazy loading
Model::preventLazyLoading(! app()->isProduction());
Model::preventLazyLoading(! App::isProduction());
Model::preventSilentlyDiscardingAttributes();
Model::preventAccessingMissingAttributes();

// https://spatie.be/docs/laravel-permission/v5/prerequisites#content-schema-limitation-in-mysql
Schema::defaultStringLength(125);

// Laravel Pulse view gate
Gate::define('viewPulse', function ($user) {
return $user->can('view_pulse');
});

// Add Spatie Health Checks
Health::checks([
UsedDiskSpaceCheck::new()->warnWhenUsedSpaceIsAbovePercentage(60)->failWhenUsedSpaceIsAbovePercentage(80),
DatabaseCheck::new(),
CacheCheck::new(),
DebugModeCheck::new(),
HorizonCheck::new(),
PingCheck::new()->url('https://api.orcid.org/')->timeout(2)->name('Orcid Api'),
RedisCheck::new(),
]);
}
}
1 change: 1 addition & 0 deletions bootstrap/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
App\Exceptions\Handler::class
);


/*
|--------------------------------------------------------------------------
| Return The Application
Expand Down
2 changes: 2 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"laravel/horizon": "^5.24.3",
"laravel/pail": "^1.1.2",
"laravel/prompts": "^0.1.21",
"laravel/pulse": "^1.2",
"laravel/sanctum": "^4.0.2",
"laravel/telescope": "^5.0.4",
"laravel/tinker": "^2.9.0",
Expand All @@ -24,6 +25,7 @@
"saloonphp/laravel-plugin": "^3.5",
"saloonphp/saloon": "^3.8.1",
"spatie/laravel-backup": "^8.8",
"spatie/laravel-health": "^1.29",
"spatie/laravel-medialibrary": "^11.4.7",
"spatie/laravel-permission": "^6.7",
"spatie/laravel-query-builder": "^5.8.0",
Expand Down
Loading

0 comments on commit 7ffd300

Please sign in to comment.