-
-
Notifications
You must be signed in to change notification settings - Fork 51
/
Notification.php
58 lines (49 loc) · 1.8 KB
/
Notification.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
<?php
namespace Spatie\FailedJobMonitor;
use Illuminate\Notifications\Messages\MailMessage;
use Illuminate\Notifications\Messages\SlackAttachment;
use Illuminate\Notifications\Messages\SlackMessage;
use Illuminate\Notifications\Notification as IlluminateNotification;
use Illuminate\Queue\Events\JobFailed;
class Notification extends IlluminateNotification
{
/** @var \Illuminate\Queue\Events\JobFailed */
protected $event;
public function via($notifiable): array
{
return config('failed-job-monitor.channels');
}
public function setEvent(JobFailed $event): self
{
$this->event = $event;
return $this;
}
public function getEvent(): JobFailed
{
return $this->event;
}
public function toMail($notifiable): MailMessage
{
return (new MailMessage)
->error()
->subject('A job failed at '.config('app.url'))
->line("Exception message: {$this->event->exception->getMessage()}")
->line("Job class: {$this->event->job->resolveName()}")
->line("Job body: {$this->event->job->getRawBody()}")
->line("Exception: {$this->event->exception->getTraceAsString()}");
}
public function toSlack(): SlackMessage
{
return (new SlackMessage)
->error()
->content('A job failed at '.config('app.url'))
->attachment(function (SlackAttachment $attachment) {
$attachment->fields([
'Exception message' => $this->event->exception->getMessage(),
'Job class' => $this->event->job->resolveName(),
'Job body' => $this->event->job->getRawBody(),
'Exception' => $this->event->exception->getTraceAsString(),
]);
});
}
}