implements ShouldQueue trong Laravel

04/01/2022   Laravel

1. Trong telescope: /telescope/jobs có
- Connection: redis | Queue: queues:default
Trong đó: 
-  Connection: redis : chính là QUEUE_CONNECTION trong .env
- QUEUE_CONNECTION = sync || database || redis ...
+ sync: chạy đồng bộ (theo thứ tự, xem như ko xử dụng queue vì chạy liền)
+ async: chạy bất đồng bộ dùng: database || redis....
- Queue: queues:default: ???

2. Khi 1 Class implements ShouldQueue
- khi app run thấy class đó (Notification, Job...) có implements ShouldQueue
=> được đẩy vào queue xử lý
=> xử dụng các methods trong trait Queueable

use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
.....

class NotifyWhenAdminChat implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable;
.....
}

 

Cám ơn

Bài viết cùng chủ đề