Answer the question
In order to leave comments, you need to log in
How to check if an event is in the queue?
I created an event and a listener according to the documentation, at the time of creating a new entry in the database. Everything works and notifications come to the mail. But how to check that it is not executed together with the user at the time of adding, but deferred?
Made it this way:
Listener
namespace App\Listeners;
use App\Events\ElementWasAdded;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Support\Facades\Mail;
class EmailElementConfirmation implements ShouldQueue
{
use InteractsWithQueue;
public function __construct()
{
//
}
public function handle(ElementWasAdded $event)
{
//
$element = $event->element;
$section = $event->section;
Mail::send('emails.ElementWasAdded', array('element' => $element, 'section' => $section), function ($message) {
$message->from('[email protected]', 'Заголовок письма');
$message->to('[email protected]');
$message->subject('Добавлен элемент');
});
}
}
namespace App\Events;
use App\Events\Event;
use Illuminate\Queue\SerializesModels;
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
class ElementWasAdded extends Event
{
use SerializesModels;
public $element;
public $section;
public function __construct($element, $section)
{
//
$this->element = $element;
$this->section = $section;
}
public function broadcastOn()
{
return [];
}
}
if($table->save()) {
$element_id = $table->id;
$section_id = "reviews_section";
Event::fire(new ElementWasAdded($element_id, $section_id));
}
Answer the question
In order to leave comments, you need to log in
Creating an email sending event with a delay of 5 seconds:
Mail::later(5, 'emails.welcome', $data, function($message)
{
$message->to('[email protected]', 'John Smith')->subject('Welcome!');
});
Stop the queue listener, run the script that adds the task to the queue, check the jobs table for the existence of the task (if you are using a database for the task queue).
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question