1. Go to this page and download the library: Download nazirul-amin/sentinel-actor library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
namespace App\Jobs;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
use NazirulAmin\SentinelActor\Traits\MonitorsExceptions;
use Throwable;
class YourJob implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels, MonitorsExceptions;
// Your job properties and methods
public function handle()
{
// Your job logic here
}
// Optional: Add context data to be sent with exception
protected function getMonitoringContextData(): array
{
return [
'job_specific_data' => $this->someProperty,
];
}
}
namespace App\Notifications;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Notifications\Notification;
use NazirulAmin\SentinelActor\Traits\MonitorsExceptions;
class YourNotification extends Notification implements ShouldQueue
{
use Queueable, MonitorsExceptions;
// Your notification properties and methods
public function via($notifiable)
{
return ['mail'];
}
public function toMail($notifiable)
{
// Your notification logic here
}
// Optional: Add context data to be sent with exception
protected function getMonitoringContextData(): array
{
return [
'notification_specific_data' => $this->someProperty,
];
}
}
namespace App\Services;
use NazirulAmin\SentinelActor\Traits\UpdatesApplicationStatus;
class HealthCheckService
{
use UpdatesApplicationStatus;
public function checkHealth()
{
try {
// Perform health checks
$isHealthy = $this->performHealthChecks();
// Send health status
$this->updateHealthStatus($isHealthy, $isHealthy ? 'Application is healthy' : 'Application is unhealthy', [
'checked_at' => now()->toISOString(),
'environment' => app()->environment(),
]);
} catch (Exception $e) {
// Send unhealthy status on error
$this->updateHealthStatus(false, 'Health check failed: ' . $e->getMessage());
}
}
private function performHealthChecks(): bool
{
// Implement your health checks here
// Return true if healthy, false if unhealthy
return true;
}
// Optional: Add context data to be sent with status updates
protected function getStatusContextData(): array
{
return [
'service_specific_data' => $this->someProperty,
];
}
}
// In your App\Console\Kernel class
protected function schedule(Schedule $schedule)
{
$schedule->command('sentinel:health-check')
->everyMinute()
->withoutOverlapping();
}
use NazirulAmin\SentinelActor\Facades\SentinelActor;
use Throwable;
try {
// Some code that might throw an exception
} catch (Throwable $exception) {
SentinelActor::sendException($exception, [
'additional_context' => 'some_value',
]);
}
use NazirulAmin\SentinelActor\Facades\SentinelActor;
SentinelActor::send('/application/events', [
'application_id' => 'your-app-name',
'application_version' => '1.0.0', // Automatically added by the package
'environment' => 'production', // Automatically added by the package
'event_type' => 'user_registered',
'level' => 'info',
'message' => 'A new user registered',
'context' => [
'user_id' => 123,
],
'timestamp' => time(),
]);
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.