send notification on update failure

This commit is contained in:
Denis Duliçi
2021-03-12 17:24:03 +03:00
parent a97709a8cb
commit 1259fa7918
9 changed files with 408 additions and 68 deletions

View File

@ -0,0 +1,51 @@
<?php
namespace App\Listeners\Update;
use App\Events\Install\UpdateFailed as Event;
use App\Notifications\Install\UpdateFailed as Notification;
use Exception;
use GuzzleHttp\Exception\RequestException;
use Illuminate\Notifications\Notifiable;
class SendNotificationOnFailure
{
/**
* Handle the event.
*
* @param $event
* @return void
*/
public function handle(Event $event)
{
$notifiable = $this->getNotifiableClass();
try {
$notifiable->notify(new Notification($event));
} catch (Exception | RequestException $e) {
report($e);
}
}
protected function getNotifiableClass()
{
return new class() {
use Notifiable;
public function routeNotificationForMail()
{
return config('update.notifications.mail.to');
}
public function routeNotificationForSlack()
{
return config('update.notifications.slack.to');
}
public function getKey()
{
return 1;
}
};
}
}