Fix exception handling in job classes

This commit is contained in:
Matteo Gheza 2024-01-17 17:54:55 +01:00
parent b04ab5aa20
commit 215b15946e
4 changed files with 50 additions and 43 deletions

View File

@ -16,49 +16,49 @@ use DefStudio\Telegraph\Facades\Telegraph;
class NotifyUsersManualModeOnJob implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
/**
* Create a new job instance.
*/
public function __construct()
{
//
/**
* Create a new job instance.
*/
public function __construct()
{
//
}
/**
* Execute the job.
*/
public function handle(): void
{
$users = TelegramBotLogins::join("users", "users.id", "=", "telegram_bot_logins.user")
->select("users.id", "chat_id", "users.available")
->where("users.availability_manual_mode", true)
->whereNotNull("chat_id")
->get();
foreach ($users as $user) {
//Get chat by id
$chat = Telegraph::chat($user["chat_id"]);
$state = $user["available"] ? "disponibile 🟢" : "non disponibile 🔴";
$chat
->message(
"⚠️ Attenzione! La tua disponibilità <b>non segue la programmazione oraria</b>." .
"\nAttualmente sei <b>$state</b>" .
"\nSe vuoi mantenere questa impostazione,\nignora questo messaggio."
)
->keyboard(Keyboard::make()->buttons([
Button::make("🔧 Ripristina programmazione 🔧")->action('manual_mode_off')->param("user_id", $user["id"]),
Button::make("🗑 Elimina notifica 🗑")->action('delete_notification')
]))
->send();
}
}
/**
* Execute the job.
*/
public function handle(): void
{
$users = TelegramBotLogins::join("users", "users.id", "=", "telegram_bot_logins.user")
->select("users.id", "chat_id", "users.available")
->where("users.availability_manual_mode", true)
->whereNotNull("chat_id")
->get();
foreach ($users as $user) {
//Get chat by id
$chat = Telegraph::chat($user["chat_id"]);
$state = $user["available"] ? "disponibile 🟢" : "non disponibile 🔴";
$chat
->message(
"⚠️ Attenzione! La tua disponibilità <b>non segue la programmazione oraria</b>.".
"\nAttualmente sei <b>$state</b>".
"\nSe vuoi mantenere questa impostazione,\nignora questo messaggio."
)
->keyboard(Keyboard::make()->buttons([
Button::make("🔧 Ripristina programmazione 🔧")->action('manual_mode_off')->param("user_id", $user["id"]),
Button::make("🗑 Elimina notifica 🗑")->action('delete_notification')
]))
->send();
}
}
public function failed(\Error|\TypeError $exception = null)
{
if (app()->bound('sentry')) {
app('sentry')->captureException($exception);
}
public function failed($exception = null)
{
if (app()->bound('sentry')) {
app('sentry')->captureException($exception);
}
}
}

View File

@ -24,4 +24,11 @@ class RemoveOldIpAddressesFromLogsJob implements ShouldQueue
Log::where('created_at', '<', Carbon::now()->subWeeks(2))
->update(['ip' => null]);
}
public function failed($exception = null)
{
if (app()->bound('sentry')) {
app('sentry')->captureException($exception);
}
}
}

View File

@ -50,7 +50,7 @@ class ResetAvailabilityMinutesJob implements ShouldQueue
}
}
public function failed(\Error|\TypeError $exception = null)
public function failed($exception = null)
{
if (app()->bound('sentry')) {
app('sentry')->captureException($exception);

View File

@ -95,7 +95,7 @@ class UpdateAvailabilityWithSchedulesJob implements ShouldQueue
TelegramBot::sendTeamMessage($text);
}
public function failed(\Error|\TypeError $exception = null)
public function failed($exception = null)
{
if (app()->bound('sentry') && !is_null($exception)) {
app('sentry')->captureException($exception);