Browse Source

Add event on the long run job

pull/1/head
Nafies Luthfi 5 years ago
parent
commit
9c9c84474c
  1. 35
      app/Events/LongRunJobDone.php
  2. 3
      app/Jobs/LongRunJob.php

35
app/Events/LongRunJobDone.php

@ -0,0 +1,35 @@
<?php
namespace App\Events;
use Illuminate\Broadcasting\Channel;
use Illuminate\Broadcasting\InteractsWithSockets;
use Illuminate\Foundation\Events\Dispatchable;
use Illuminate\Queue\SerializesModels;
class LongRunJobDone
{
public $message;
use Dispatchable, InteractsWithSockets, SerializesModels;
/**
* Create a new event instance.
*
* @return void
*/
public function __construct($message)
{
$this->message = $message;
}
/**
* Get the channels the event should broadcast on.
*
* @return \Illuminate\Broadcasting\Channel|array
*/
public function broadcastOn()
{
return new Channel('queue-notifier');
}
}

3
app/Jobs/LongRunJob.php

@ -2,6 +2,7 @@
namespace App\Jobs;
use App\Events\LongRunJobDone;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
@ -21,6 +22,6 @@ class LongRunJob implements ShouldQueue
{
sleep(3);
app('session')->flash('flash_notification.message', 'Long run job done.');
event(new LongRunJobDone('Long run job done.'));
}
}
Loading…
Cancel
Save