Monitor jobs and Telegram bot using Sentry

This commit is contained in:
Matteo Gheza 2023-09-02 22:26:27 +02:00
parent f0c3c807ac
commit 6e13e6de70
6 changed files with 47 additions and 4 deletions

View File

@ -16,9 +16,15 @@ class Kernel extends ConsoleKernel
*/
protected function schedule(Schedule $schedule): void
{
$schedule->job(new UpdateAvailabilityWithSchedulesJob)->everyThirtyMinutes();
$schedule->job(new NotifyUsersManualModeOn)->dailyAt('7:00');
$schedule->job(new ResetAvailabilityMinutes)->monthlyOn(1, '0:00');
$schedule->job(new UpdateAvailabilityWithSchedulesJob)
->everyThirtyMinutes()
->sentryMonitor();
$schedule->job(new NotifyUsersManualModeOn)
->dailyAt('7:00')
->sentryMonitor();
$schedule->job(new ResetAvailabilityMinutes)
->monthlyOn(1, '0:00')
->sentryMonitor();
}
/**

View File

@ -53,4 +53,11 @@ class NotifyUsersManualModeOn implements ShouldQueue
->send();
}
}
public function failed(\Exception $exception)
{
if (app()->bound('sentry')) {
app('sentry')->captureException($exception);
}
}
}

View File

@ -49,4 +49,11 @@ class ResetAvailabilityMinutes implements ShouldQueue
$row->save();
}
}
public function failed(\Exception $exception)
{
if (app()->bound('sentry')) {
app('sentry')->captureException($exception);
}
}
}

View File

@ -96,4 +96,11 @@ class UpdateAvailabilityWithSchedulesJob implements ShouldQueue
}
}
}
public function failed(\Exception $exception)
{
if (app()->bound('sentry')) {
app('sentry')->captureException($exception);
}
}
}

View File

@ -9,6 +9,8 @@ use App\Utils\Availability;
use DefStudio\Telegraph\Facades\Telegraph;
use Sentry\State\Scope;
class WebhookController extends
\DefStudio\Telegraph\Handlers\WebhookHandler
{
@ -27,6 +29,16 @@ class WebhookController extends
private function user(): User|null {
if($this->user) return $this->user;
$this->user = $this->message->from()->storage()->get('user');
if(app()->bound('sentry')) {
\Sentry\configureScope(function (Scope $scope): void {
$scope->setUser([
'id' => $this->user->id,
'name' => $this->user->name,
]);
});
}
return $this->user;
}

View File

@ -53,10 +53,14 @@ return [
'channels' => [
'stack' => [
'driver' => 'stack',
'channels' => ['single'],
'channels' => ['single', 'sentry'],
'ignore_exceptions' => false,
],
'sentry' => [
'driver' => 'sentry',
],
'single' => [
'driver' => 'single',
'path' => storage_path('logs/laravel.log'),