Skip to content

Commit 3193c5f

Browse files
author
dante
committed
Notification when job is completed
1 parent 5f731ca commit 3193c5f

2 files changed

Lines changed: 90 additions & 0 deletions

File tree

‎ProcessMaker/Jobs/CompileSass.php‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88
use Illuminate\Contracts\Queue\ShouldQueue;
99
use Illuminate\Foundation\Bus\Dispatchable;
1010
use Illuminate\Support\Facades\Log;
11+
use Illuminate\Support\Facades\Notification;
12+
use ProcessMaker\Models\User;
13+
use ProcessMaker\Notifications\SassCompiledNotification;
1114

1215
class CompileSass implements ShouldQueue
1316
{
@@ -49,6 +52,10 @@ public function handle()
4952
if (str_contains($this->properties['tag'], 'app')) {
5053
$this->fixPathsInGeneratedAppCss();
5154
}
55+
56+
if (str_contains($this->properties['tag'], 'queues')) {
57+
Notification::send(collect([User::find(1)]), new SassCompiledNotification());
58+
}
5259
}
5360

5461
/**
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
<?php
2+
3+
namespace ProcessMaker\Notifications;
4+
5+
use Carbon\Carbon;
6+
use Illuminate\Bus\Queueable;
7+
use Illuminate\Notifications\Messages\BroadcastMessage;
8+
use Illuminate\Notifications\Messages\MailMessage;
9+
use Illuminate\Notifications\Notification;
10+
use ProcessMaker\Models\ProcessRequest as Instance;
11+
use ProcessMaker\Nayra\Contracts\Engine\ExecutionInstanceInterface;
12+
13+
class SassCompiledNotification extends Notification
14+
{
15+
use Queueable;
16+
17+
private $processUid;
18+
private $processName;
19+
private $instanceUid;
20+
21+
/**
22+
* Create a new notification instance.
23+
*
24+
* @return void
25+
*/
26+
public function __construct()
27+
{
28+
}
29+
30+
/**
31+
* Get the notification's delivery channels.
32+
*
33+
* @param mixed $notifiable
34+
* @return array
35+
*/
36+
public function via($notifiable)
37+
{
38+
return ['broadcast', 'database'];
39+
}
40+
41+
/**
42+
* Get the mail representation of the notification.
43+
*
44+
* @param mixed $notifiable
45+
* @return \Illuminate\Notifications\Messages\MailMessage
46+
*/
47+
public function toMail($notifiable)
48+
{
49+
return (new MailMessage)
50+
->line('The introduction to the notification.')
51+
->action('Notification Action', url('/'))
52+
->line('Thank you for using our application!');
53+
}
54+
55+
public function toDatabase($notifiable)
56+
{
57+
return $this->toArray($notifiable);
58+
}
59+
60+
/**
61+
* Get the array representation of the notification.
62+
*
63+
* @param mixed $notifiable
64+
* @return array
65+
*/
66+
public function toArray($notifiable)
67+
{
68+
return [
69+
'type' => 'SASS_COMPILE_COMPLETED',
70+
'name' => 'Sass compile completed',
71+
'dateTime' => Carbon::today()->toIso8601String(),
72+
'uid' => 1,
73+
'request_id' => 1,
74+
'url' => 'http://test.com'
75+
];
76+
}
77+
78+
public function toBroadcast($notifiable)
79+
{
80+
return new BroadcastMessage($this->toArray($notifiable));
81+
}
82+
83+
}

0 commit comments

Comments
 (0)