Việc làm php laravel

{tip} Laravel hiện cung cấp Horizon, một bảng điều khiển đẹp mắt và hệ thống cấu hình cho hàng đợi do Redis cung cấp của bạn. Kiểm tra tài liệu Horizon đầy đủ để biết thêm thông tin

Hàng đợi của Laravel cung cấp một API thống nhất trên nhiều phụ trợ hàng đợi khác nhau, chẳng hạn như Beanstalk, Amazon SQS, Redis hoặc thậm chí là cơ sở dữ liệu quan hệ. Hàng đợi cho phép bạn trì hoãn việc xử lý một tác vụ tốn thời gian, chẳng hạn như gửi email, cho đến một thời điểm sau đó. Việc trì hoãn các tác vụ tốn thời gian này sẽ tăng tốc đáng kể các yêu cầu web tới ứng dụng của bạn

Tệp cấu hình hàng đợi được lưu trữ trong

use Illuminate\Bus\Queueable;

use Illuminate\Queue\SerializesModels;

use Illuminate\Queue\InteractsWithQueue;

use Illuminate\Contracts\Queue\ShouldQueue;

use Illuminate\Foundation\Bus\Dispatchable;

class ProcessPodcast implements ShouldQueue

use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

* Create a new job instance.

public function __construct(Podcast $podcast)

* @param AudioProcessor $processor

public function handle(AudioProcessor $processor)

// Process uploaded podcast...

3. Trong tệp này, bạn sẽ tìm thấy các cấu hình kết nối cho từng trình điều khiển hàng đợi đi kèm với khung, bao gồm cơ sở dữ liệu, Beanstalkd, Amazon SQS, Redis và trình điều khiển đồng bộ sẽ thực thi công việc ngay lập tức (để sử dụng cục bộ). Trình điều khiển hàng đợi

use Illuminate\Bus\Queueable;

use Illuminate\Queue\SerializesModels;

use Illuminate\Queue\InteractsWithQueue;

use Illuminate\Contracts\Queue\ShouldQueue;

use Illuminate\Foundation\Bus\Dispatchable;

class ProcessPodcast implements ShouldQueue

use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

* Create a new job instance.

public function __construct(Podcast $podcast)

* @param AudioProcessor $processor

public function handle(AudioProcessor $processor)

// Process uploaded podcast...

4 cũng được bao gồm để loại bỏ các công việc được xếp hàng đợi

Kết nối Vs. hàng đợi

Trước khi bắt đầu với hàng đợi Laravel, điều quan trọng là phải hiểu sự khác biệt giữa "kết nối" và "hàng đợi". Trong tệp cấu hình

use Illuminate\Bus\Queueable;

use Illuminate\Queue\SerializesModels;

use Illuminate\Queue\InteractsWithQueue;

use Illuminate\Contracts\Queue\ShouldQueue;

use Illuminate\Foundation\Bus\Dispatchable;

class ProcessPodcast implements ShouldQueue

use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

* Create a new job instance.

public function __construct(Podcast $podcast)

* @param AudioProcessor $processor

public function handle(AudioProcessor $processor)

// Process uploaded podcast...

3 của bạn, có tùy chọn cấu hình

use Illuminate\Bus\Queueable;

use Illuminate\Queue\SerializesModels;

use Illuminate\Queue\InteractsWithQueue;

use Illuminate\Contracts\Queue\ShouldQueue;

use Illuminate\Foundation\Bus\Dispatchable;

class ProcessPodcast implements ShouldQueue

use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

* Create a new job instance.

public function __construct(Podcast $podcast)

* @param AudioProcessor $processor

public function handle(AudioProcessor $processor)

// Process uploaded podcast...

6. Tùy chọn này xác định một kết nối cụ thể tới dịch vụ phụ trợ, chẳng hạn như Amazon SQS, Beanstalk hoặc Redis. Tuy nhiên, bất kỳ kết nối hàng đợi cụ thể nào cũng có thể có nhiều "hàng đợi" có thể được coi là các ngăn xếp hoặc chồng công việc được xếp hàng khác nhau

Lưu ý rằng mỗi ví dụ cấu hình kết nối trong tệp cấu hình

use Illuminate\Bus\Queueable;

use Illuminate\Queue\SerializesModels;

use Illuminate\Queue\InteractsWithQueue;

use Illuminate\Contracts\Queue\ShouldQueue;

use Illuminate\Foundation\Bus\Dispatchable;

class ProcessPodcast implements ShouldQueue

use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

* Create a new job instance.

public function __construct(Podcast $podcast)

* @param AudioProcessor $processor

public function handle(AudioProcessor $processor)

// Process uploaded podcast...

7 chứa thuộc tính

use Illuminate\Bus\Queueable;

use Illuminate\Queue\SerializesModels;

use Illuminate\Queue\InteractsWithQueue;

use Illuminate\Contracts\Queue\ShouldQueue;

use Illuminate\Foundation\Bus\Dispatchable;

class ProcessPodcast implements ShouldQueue

use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

* Create a new job instance.

public function __construct(Podcast $podcast)

* @param AudioProcessor $processor

public function handle(AudioProcessor $processor)

// Process uploaded podcast...

7. Đây là hàng đợi mặc định mà các công việc sẽ được gửi đến khi chúng được gửi đến một kết nối nhất định. Nói cách khác, nếu bạn gửi một công việc mà không xác định rõ ràng công việc đó sẽ được gửi đến hàng đợi nào, thì công việc đó sẽ được đặt trên hàng đợi được xác định trong thuộc tính

use Illuminate\Bus\Queueable;

use Illuminate\Queue\SerializesModels;

use Illuminate\Queue\InteractsWithQueue;

use Illuminate\Contracts\Queue\ShouldQueue;

use Illuminate\Foundation\Bus\Dispatchable;

class ProcessPodcast implements ShouldQueue

use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

* Create a new job instance.

public function __construct(Podcast $podcast)

* @param AudioProcessor $processor

public function handle(AudioProcessor $processor)

// Process uploaded podcast...

7 của cấu hình kết nối

// This job is sent to the default queue...

// This job is sent to the "emails" queue...

Job::dispatch()->onQueue('emails');

Một số ứng dụng có thể không cần đẩy công việc lên nhiều hàng đợi, thay vào đó, ưu tiên có một hàng đợi đơn giản. Tuy nhiên, đẩy công việc vào nhiều hàng đợi có thể đặc biệt hữu ích cho các ứng dụng muốn ưu tiên hoặc phân đoạn cách xử lý công việc, vì queue worker của Laravel cho phép bạn chỉ định hàng đợi nào nó sẽ xử lý theo mức độ ưu tiên. Ví dụ: nếu bạn đẩy công việc vào hàng đợi

namespace App\Http\Controllers;

use App\Jobs\ProcessPodcast;

use Illuminate\Http\Request;

use App\Http\Controllers\Controller;

class PodcastController extends Controller

public function store(Request $request)

ProcessPodcast::dispatch($podcast);

0, bạn có thể chạy một công nhân mang lại cho họ mức độ ưu tiên xử lý cao hơn

php artisan queue:work --queue=high,default

Điều kiện tiên quyết của trình điều khiển

cơ sở dữ liệu

Để sử dụng trình điều khiển hàng đợi

namespace App\Http\Controllers;

use App\Jobs\ProcessPodcast;

use Illuminate\Http\Request;

use App\Http\Controllers\Controller;

class PodcastController extends Controller

public function store(Request $request)

ProcessPodcast::dispatch($podcast);

1, bạn sẽ cần một bảng cơ sở dữ liệu để giữ các công việc. Để tạo di chuyển tạo bảng này, hãy chạy lệnh Artisan

namespace App\Http\Controllers;

use App\Jobs\ProcessPodcast;

use Illuminate\Http\Request;

use App\Http\Controllers\Controller;

class PodcastController extends Controller

public function store(Request $request)

ProcessPodcast::dispatch($podcast);

2. Khi quá trình di chuyển đã được tạo, bạn có thể di chuyển cơ sở dữ liệu của mình bằng lệnh

namespace App\Http\Controllers;

use App\Jobs\ProcessPodcast;

use Illuminate\Http\Request;

use App\Http\Controllers\Controller;

class PodcastController extends Controller

public function store(Request $request)

ProcessPodcast::dispatch($podcast);

3

làm lại

Để sử dụng trình điều khiển hàng đợi

namespace App\Http\Controllers;

use App\Jobs\ProcessPodcast;

use Illuminate\Http\Request;

use App\Http\Controllers\Controller;

class PodcastController extends Controller

public function store(Request $request)

ProcessPodcast::dispatch($podcast);

4, bạn nên định cấu hình kết nối cơ sở dữ liệu Redis trong tệp cấu hình

namespace App\Http\Controllers;

use App\Jobs\ProcessPodcast;

use Illuminate\Http\Request;

use App\Http\Controllers\Controller;

class PodcastController extends Controller

public function store(Request $request)

ProcessPodcast::dispatch($podcast);

5 của mình

Nếu kết nối hàng đợi Redis của bạn sử dụng Cụm Redis, tên hàng đợi của bạn phải chứa một. Điều này là bắt buộc để đảm bảo tất cả các khóa Redis cho một hàng đợi nhất định được đặt vào cùng một vị trí băm

Các điều kiện tiên quyết khác của trình điều khiển

Các phụ thuộc sau đây là cần thiết cho trình điều khiển hàng đợi được liệt kê

-Amazon SQS. `aws/aws-sdk-php ~3. 0` - Cây đậu. `pda/pheanstalk ~3. 0` - Redis. `predis/predis ~1. 0`

Tạo công việc

Tạo các lớp công việc

Theo mặc định, tất cả các công việc có thể xếp hàng cho ứng dụng của bạn được lưu trữ trong thư mục

namespace App\Http\Controllers;

use App\Jobs\ProcessPodcast;

use Illuminate\Http\Request;

use App\Http\Controllers\Controller;

class PodcastController extends Controller

public function store(Request $request)

ProcessPodcast::dispatch($podcast);

6. Nếu thư mục

namespace App\Http\Controllers;

use App\Jobs\ProcessPodcast;

use Illuminate\Http\Request;

use App\Http\Controllers\Controller;

class PodcastController extends Controller

public function store(Request $request)

ProcessPodcast::dispatch($podcast);

6 không tồn tại, nó sẽ được tạo khi bạn chạy lệnh

namespace App\Http\Controllers;

use App\Jobs\ProcessPodcast;

use Illuminate\Http\Request;

use App\Http\Controllers\Controller;

class PodcastController extends Controller

public function store(Request $request)

ProcessPodcast::dispatch($podcast);

8 Artisan. Bạn có thể tạo một queued job mới bằng Artisan CLI

use Illuminate\Bus\Queueable;

use Illuminate\Queue\SerializesModels;

use Illuminate\Queue\InteractsWithQueue;

use Illuminate\Contracts\Queue\ShouldQueue;

use Illuminate\Foundation\Bus\Dispatchable;

class ProcessPodcast implements ShouldQueue

use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

* Create a new job instance.

public function __construct(Podcast $podcast)

* @param AudioProcessor $processor

public function handle(AudioProcessor $processor)

// Process uploaded podcast...

8

Lớp được tạo sẽ triển khai giao diện

namespace App\Http\Controllers;

use App\Jobs\ProcessPodcast;

use Illuminate\Http\Request;

use App\Http\Controllers\Controller;

class PodcastController extends Controller

public function store(Request $request)

ProcessPodcast::dispatch($podcast);

9, cho Laravel biết rằng công việc sẽ được đẩy vào hàng đợi để chạy không đồng bộ

Cấu trúc lớp học

Các lớp công việc rất đơn giản, thường chỉ chứa một phương thức

use Illuminate\Bus\Queueable;

use Illuminate\Queue\SerializesModels;

use Illuminate\Queue\InteractsWithQueue;

use Illuminate\Contracts\Queue\ShouldQueue;

use Illuminate\Foundation\Bus\Dispatchable;

class ProcessPodcast implements ShouldQueue

use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

* Create a new job instance.

public function __construct(Podcast $podcast)

* @param AudioProcessor $processor

public function handle(AudioProcessor $processor)

// Process uploaded podcast...

00 được gọi khi công việc được xử lý bởi hàng đợi. Để bắt đầu, chúng ta hãy xem một lớp công việc ví dụ. Trong ví dụ này, chúng tôi sẽ giả vờ rằng chúng tôi quản lý một dịch vụ xuất bản podcast và cần xử lý các tệp podcast đã tải lên trước khi chúng được xuất bản

use Illuminate\Bus\Queueable;

use Illuminate\Queue\SerializesModels;

use Illuminate\Queue\InteractsWithQueue;

use Illuminate\Contracts\Queue\ShouldQueue;

use Illuminate\Foundation\Bus\Dispatchable;

class ProcessPodcast implements ShouldQueue

use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

* Create a new job instance.

public function __construct(Podcast $podcast)

* @param AudioProcessor $processor

public function handle(AudioProcessor $processor)

// Process uploaded podcast...

Trong ví dụ này, lưu ý rằng chúng ta có thể chuyển trực tiếp một Eloquent model vào hàm tạo của queued job. Do đặc điểm

use Illuminate\Bus\Queueable;

use Illuminate\Queue\SerializesModels;

use Illuminate\Queue\InteractsWithQueue;

use Illuminate\Contracts\Queue\ShouldQueue;

use Illuminate\Foundation\Bus\Dispatchable;

class ProcessPodcast implements ShouldQueue

use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

* Create a new job instance.

public function __construct(Podcast $podcast)

* @param AudioProcessor $processor

public function handle(AudioProcessor $processor)

// Process uploaded podcast...

01 mà công việc đang sử dụng, các mô hình Eloquent sẽ được tuần tự hóa và hủy tuần tự hóa một cách duyên dáng khi công việc đang xử lý. Nếu queued job của bạn chấp nhận một Eloquent model trong hàm khởi tạo của nó, thì chỉ mã định danh cho model đó sẽ được tuần tự hóa vào queue. Khi công việc thực sự được xử lý, hệ thống xếp hàng sẽ tự động truy xuất lại phiên bản mô hình đầy đủ từ cơ sở dữ liệu. Tất cả đều hoàn toàn trong suốt đối với ứng dụng của bạn và ngăn chặn các sự cố có thể phát sinh từ việc tuần tự hóa các phiên bản mô hình Eloquent đầy đủ

Phương thức

use Illuminate\Bus\Queueable;

use Illuminate\Queue\SerializesModels;

use Illuminate\Queue\InteractsWithQueue;

use Illuminate\Contracts\Queue\ShouldQueue;

use Illuminate\Foundation\Bus\Dispatchable;

class ProcessPodcast implements ShouldQueue

use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

* Create a new job instance.

public function __construct(Podcast $podcast)

* @param AudioProcessor $processor

public function handle(AudioProcessor $processor)

// Process uploaded podcast...

00 được gọi khi công việc được xử lý bởi hàng đợi. Lưu ý rằng chúng tôi có thể gõ phụ thuộc gợi ý vào phương pháp

use Illuminate\Bus\Queueable;

use Illuminate\Queue\SerializesModels;

use Illuminate\Queue\InteractsWithQueue;

use Illuminate\Contracts\Queue\ShouldQueue;

use Illuminate\Foundation\Bus\Dispatchable;

class ProcessPodcast implements ShouldQueue

use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

* Create a new job instance.

public function __construct(Podcast $podcast)

* @param AudioProcessor $processor

public function handle(AudioProcessor $processor)

// Process uploaded podcast...

00 của công việc. Laravel service container tự động inject các phụ thuộc này

{note} Dữ liệu nhị phân, chẳng hạn như nội dung hình ảnh thô, phải được chuyển qua hàm

use Illuminate\Bus\Queueable;

use Illuminate\Queue\SerializesModels;

use Illuminate\Queue\InteractsWithQueue;

use Illuminate\Contracts\Queue\ShouldQueue;

use Illuminate\Foundation\Bus\Dispatchable;

class ProcessPodcast implements ShouldQueue

use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

* Create a new job instance.

public function __construct(Podcast $podcast)

* @param AudioProcessor $processor

public function handle(AudioProcessor $processor)

// Process uploaded podcast...

04 trước khi được chuyển tới công việc đã xếp hàng. Mặt khác, công việc có thể không được tuần tự hóa thành JSON khi được đặt trên hàng đợi

điều phối công việc

Khi bạn đã viết lớp công việc của mình, bạn có thể gửi nó bằng cách sử dụng phương pháp

use Illuminate\Bus\Queueable;

use Illuminate\Queue\SerializesModels;

use Illuminate\Queue\InteractsWithQueue;

use Illuminate\Contracts\Queue\ShouldQueue;

use Illuminate\Foundation\Bus\Dispatchable;

class ProcessPodcast implements ShouldQueue

use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

* Create a new job instance.

public function __construct(Podcast $podcast)

* @param AudioProcessor $processor

public function handle(AudioProcessor $processor)

// Process uploaded podcast...

05 trên chính công việc đó. Các đối số được truyền cho phương thức

use Illuminate\Bus\Queueable;

use Illuminate\Queue\SerializesModels;

use Illuminate\Queue\InteractsWithQueue;

use Illuminate\Contracts\Queue\ShouldQueue;

use Illuminate\Foundation\Bus\Dispatchable;

class ProcessPodcast implements ShouldQueue

use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

* Create a new job instance.

public function __construct(Podcast $podcast)

* @param AudioProcessor $processor

public function handle(AudioProcessor $processor)

// Process uploaded podcast...

05 sẽ được trao cho hàm tạo của công việc

________số 8

Gửi hàng bị trì hoãn

Nếu bạn muốn trì hoãn việc thực hiện một queued job, bạn có thể sử dụng phương thức

use Illuminate\Bus\Queueable;

use Illuminate\Queue\SerializesModels;

use Illuminate\Queue\InteractsWithQueue;

use Illuminate\Contracts\Queue\ShouldQueue;

use Illuminate\Foundation\Bus\Dispatchable;

class ProcessPodcast implements ShouldQueue

use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

* Create a new job instance.

public function __construct(Podcast $podcast)

* @param AudioProcessor $processor

public function handle(AudioProcessor $processor)

// Process uploaded podcast...

07 khi gửi một job. Ví dụ: hãy chỉ định rằng một công việc sẽ không có sẵn để xử lý cho đến 10 phút sau khi nó được gửi đi

use Illuminate\Bus\Queueable;

use Illuminate\Queue\SerializesModels;

use Illuminate\Queue\InteractsWithQueue;

use Illuminate\Contracts\Queue\ShouldQueue;

use Illuminate\Foundation\Bus\Dispatchable;

class ProcessPodcast implements ShouldQueue

use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

* Create a new job instance.

public function __construct(Podcast $podcast)

* @param AudioProcessor $processor

public function handle(AudioProcessor $processor)

// Process uploaded podcast...

0

{note} Dịch vụ xếp hàng Amazon SQS có thời gian trễ tối đa là 15 phút

chuỗi công việc

Chuỗi công việc cho phép bạn chỉ định danh sách các công việc được xếp hàng đợi sẽ được chạy theo trình tự. Nếu một công việc trong chuỗi không thành công, các công việc còn lại sẽ không được chạy. Để thực hiện chuỗi công việc được xếp hàng đợi, bạn có thể sử dụng phương thức

use Illuminate\Bus\Queueable;

use Illuminate\Queue\SerializesModels;

use Illuminate\Queue\InteractsWithQueue;

use Illuminate\Contracts\Queue\ShouldQueue;

use Illuminate\Foundation\Bus\Dispatchable;

class ProcessPodcast implements ShouldQueue

use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

* Create a new job instance.

public function __construct(Podcast $podcast)

* @param AudioProcessor $processor

public function handle(AudioProcessor $processor)

// Process uploaded podcast...

08 trên bất kỳ công việc có thể gửi đi nào của mình

use Illuminate\Bus\Queueable;

use Illuminate\Queue\SerializesModels;

use Illuminate\Queue\InteractsWithQueue;

use Illuminate\Contracts\Queue\ShouldQueue;

use Illuminate\Foundation\Bus\Dispatchable;

class ProcessPodcast implements ShouldQueue

use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

* Create a new job instance.

public function __construct(Podcast $podcast)

* @param AudioProcessor $processor

public function handle(AudioProcessor $processor)

// Process uploaded podcast...

2

Tùy chỉnh hàng đợi & kết nối

Gửi đến một hàng đợi cụ thể

Bằng cách đẩy các công việc vào các hàng đợi khác nhau, bạn có thể "phân loại" các công việc được xếp hàng đợi của mình và thậm chí ưu tiên số lượng công nhân mà bạn chỉ định cho các hàng đợi khác nhau. Hãy nhớ rằng, điều này không đẩy các công việc đến các "kết nối" hàng đợi khác nhau như được xác định bởi tệp cấu hình hàng đợi của bạn, mà chỉ đẩy các hàng đợi cụ thể trong một kết nối duy nhất. Để chỉ định hàng đợi, hãy sử dụng phương pháp

use Illuminate\Bus\Queueable;

use Illuminate\Queue\SerializesModels;

use Illuminate\Queue\InteractsWithQueue;

use Illuminate\Contracts\Queue\ShouldQueue;

use Illuminate\Foundation\Bus\Dispatchable;

class ProcessPodcast implements ShouldQueue

use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

* Create a new job instance.

public function __construct(Podcast $podcast)

* @param AudioProcessor $processor

public function handle(AudioProcessor $processor)

// Process uploaded podcast...

09 khi gửi công việc

use Illuminate\Bus\Queueable;

use Illuminate\Queue\SerializesModels;

use Illuminate\Queue\InteractsWithQueue;

use Illuminate\Contracts\Queue\ShouldQueue;

use Illuminate\Foundation\Bus\Dispatchable;

class ProcessPodcast implements ShouldQueue

use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

* Create a new job instance.

public function __construct(Podcast $podcast)

* @param AudioProcessor $processor

public function handle(AudioProcessor $processor)

// Process uploaded podcast...

4

Gửi đến một kết nối cụ thể

Nếu bạn đang làm việc với nhiều kết nối hàng đợi, bạn có thể chỉ định kết nối nào sẽ đẩy công việc tới. Để chỉ định kết nối, hãy sử dụng phương pháp

use Illuminate\Bus\Queueable;

use Illuminate\Queue\SerializesModels;

use Illuminate\Queue\InteractsWithQueue;

use Illuminate\Contracts\Queue\ShouldQueue;

use Illuminate\Foundation\Bus\Dispatchable;

class ProcessPodcast implements ShouldQueue

use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

* Create a new job instance.

public function __construct(Podcast $podcast)

* @param AudioProcessor $processor

public function handle(AudioProcessor $processor)

// Process uploaded podcast...

20 khi gửi công việc

use Illuminate\Bus\Queueable;

use Illuminate\Queue\SerializesModels;

use Illuminate\Queue\InteractsWithQueue;

use Illuminate\Contracts\Queue\ShouldQueue;

use Illuminate\Foundation\Bus\Dispatchable;

class ProcessPodcast implements ShouldQueue

use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

* Create a new job instance.

public function __construct(Podcast $podcast)

* @param AudioProcessor $processor

public function handle(AudioProcessor $processor)

// Process uploaded podcast...

6

Tất nhiên, bạn có thể xâu chuỗi các phương thức

use Illuminate\Bus\Queueable;

use Illuminate\Queue\SerializesModels;

use Illuminate\Queue\InteractsWithQueue;

use Illuminate\Contracts\Queue\ShouldQueue;

use Illuminate\Foundation\Bus\Dispatchable;

class ProcessPodcast implements ShouldQueue

use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

* Create a new job instance.

public function __construct(Podcast $podcast)

* @param AudioProcessor $processor

public function handle(AudioProcessor $processor)

// Process uploaded podcast...

20 và

use Illuminate\Bus\Queueable;

use Illuminate\Queue\SerializesModels;

use Illuminate\Queue\InteractsWithQueue;

use Illuminate\Contracts\Queue\ShouldQueue;

use Illuminate\Foundation\Bus\Dispatchable;

class ProcessPodcast implements ShouldQueue

use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

* Create a new job instance.

public function __construct(Podcast $podcast)

* @param AudioProcessor $processor

public function handle(AudioProcessor $processor)

// Process uploaded podcast...

09 để chỉ định kết nối và hàng đợi cho một công việc

use Illuminate\Bus\Queueable;

use Illuminate\Queue\SerializesModels;

use Illuminate\Queue\InteractsWithQueue;

use Illuminate\Contracts\Queue\ShouldQueue;

use Illuminate\Foundation\Bus\Dispatchable;

class ProcessPodcast implements ShouldQueue

use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

* Create a new job instance.

public function __construct(Podcast $podcast)

* @param AudioProcessor $processor

public function handle(AudioProcessor $processor)

// Process uploaded podcast...

9

Chỉ định số lần thử công việc tối đa/giá trị thời gian chờ

Số lần thử tối đa

Một cách tiếp cận để chỉ định số lần tối đa một công việc có thể được thực hiện là thông qua công tắc

use Illuminate\Bus\Queueable;

use Illuminate\Queue\SerializesModels;

use Illuminate\Queue\InteractsWithQueue;

use Illuminate\Contracts\Queue\ShouldQueue;

use Illuminate\Foundation\Bus\Dispatchable;

class ProcessPodcast implements ShouldQueue

use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

* Create a new job instance.

public function __construct(Podcast $podcast)

* @param AudioProcessor $processor

public function handle(AudioProcessor $processor)

// Process uploaded podcast...

23 trên dòng lệnh Artisan

php artisan queue:work --queue=high,default

0

Tuy nhiên, bạn có thể thực hiện một cách tiếp cận chi tiết hơn bằng cách xác định số lần thử tối đa trên chính lớp công việc đó. Nếu số lần thử tối đa được chỉ định trong công việc, thì nó sẽ được ưu tiên hơn giá trị được cung cấp trên dòng lệnh

php artisan queue:work --queue=high,default

1

Nỗ lực dựa trên thời gian

Thay thế cho việc xác định số lần công việc có thể được thử trước khi thất bại, bạn có thể xác định thời gian mà công việc sẽ hết thời gian chờ. Điều này cho phép một công việc được thực hiện nhiều lần trong một khung thời gian nhất định. Để xác định thời gian mà một công việc sẽ hết thời gian chờ, hãy thêm một phương thức

use Illuminate\Bus\Queueable;

use Illuminate\Queue\SerializesModels;

use Illuminate\Queue\InteractsWithQueue;

use Illuminate\Contracts\Queue\ShouldQueue;

use Illuminate\Foundation\Bus\Dispatchable;

class ProcessPodcast implements ShouldQueue

use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

* Create a new job instance.

public function __construct(Podcast $podcast)

* @param AudioProcessor $processor

public function handle(AudioProcessor $processor)

// Process uploaded podcast...

24 vào lớp công việc của bạn

php artisan queue:work --queue=high,default

2

{tip} Bạn cũng có thể xác định phương thức

use Illuminate\Bus\Queueable;

use Illuminate\Queue\SerializesModels;

use Illuminate\Queue\InteractsWithQueue;

use Illuminate\Contracts\Queue\ShouldQueue;

use Illuminate\Foundation\Bus\Dispatchable;

class ProcessPodcast implements ShouldQueue

use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

* Create a new job instance.

public function __construct(Podcast $podcast)

* @param AudioProcessor $processor

public function handle(AudioProcessor $processor)

// Process uploaded podcast...

24 trên các trình lắng nghe sự kiện được xếp hàng đợi của mình

Hết giờ

{note} Tính năng

use Illuminate\Bus\Queueable;

use Illuminate\Queue\SerializesModels;

use Illuminate\Queue\InteractsWithQueue;

use Illuminate\Contracts\Queue\ShouldQueue;

use Illuminate\Foundation\Bus\Dispatchable;

class ProcessPodcast implements ShouldQueue

use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

* Create a new job instance.

public function __construct(Podcast $podcast)

* @param AudioProcessor $processor

public function handle(AudioProcessor $processor)

// Process uploaded podcast...

26 được tối ưu hóa cho PHP 7. 1+ và phần mở rộng PHP

use Illuminate\Bus\Queueable;

use Illuminate\Queue\SerializesModels;

use Illuminate\Queue\InteractsWithQueue;

use Illuminate\Contracts\Queue\ShouldQueue;

use Illuminate\Foundation\Bus\Dispatchable;

class ProcessPodcast implements ShouldQueue

use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

* Create a new job instance.

public function __construct(Podcast $podcast)

* @param AudioProcessor $processor

public function handle(AudioProcessor $processor)

// Process uploaded podcast...

27

Tương tự như vậy, số giây tối đa mà công việc có thể chạy có thể được chỉ định bằng cách sử dụng công tắc

use Illuminate\Bus\Queueable;

use Illuminate\Queue\SerializesModels;

use Illuminate\Queue\InteractsWithQueue;

use Illuminate\Contracts\Queue\ShouldQueue;

use Illuminate\Foundation\Bus\Dispatchable;

class ProcessPodcast implements ShouldQueue

use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

* Create a new job instance.

public function __construct(Podcast $podcast)

* @param AudioProcessor $processor

public function handle(AudioProcessor $processor)

// Process uploaded podcast...

28 trên dòng lệnh Artisan

php artisan queue:work --queue=high,default

3

Tuy nhiên, bạn cũng có thể xác định số giây tối đa mà một công việc sẽ được phép chạy trên chính lớp công việc đó. Nếu thời gian chờ được chỉ định trong công việc, nó sẽ được ưu tiên hơn bất kỳ thời gian chờ nào được chỉ định trên dòng lệnh

php artisan queue:work --queue=high,default

4

Giới hạn tỷ lệ

{note} Tính năng này yêu cầu ứng dụng của bạn có thể tương tác với máy chủ Redis

Nếu ứng dụng của bạn tương tác với Redis, bạn có thể điều chỉnh các công việc được xếp hàng đợi của mình theo thời gian hoặc đồng thời. Tính năng này có thể hỗ trợ khi các công việc được xếp hàng đợi của bạn đang tương tác với các API cũng bị giới hạn tốc độ. Ví dụ: sử dụng phương pháp

use Illuminate\Bus\Queueable;

use Illuminate\Queue\SerializesModels;

use Illuminate\Queue\InteractsWithQueue;

use Illuminate\Contracts\Queue\ShouldQueue;

use Illuminate\Foundation\Bus\Dispatchable;

class ProcessPodcast implements ShouldQueue

use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

* Create a new job instance.

public function __construct(Podcast $podcast)

* @param AudioProcessor $processor

public function handle(AudioProcessor $processor)

// Process uploaded podcast...

29, bạn có thể điều chỉnh một loại công việc nhất định để chỉ chạy 10 lần sau mỗi 60 giây. Nếu không thể lấy được khóa, thông thường bạn nên giải phóng công việc trở lại hàng đợi để có thể thử lại sau

php artisan queue:work --queue=high,default

5

{tip} Trong ví dụ trên,

use Illuminate\Bus\Queueable;

use Illuminate\Queue\SerializesModels;

use Illuminate\Queue\InteractsWithQueue;

use Illuminate\Contracts\Queue\ShouldQueue;

use Illuminate\Foundation\Bus\Dispatchable;

class ProcessPodcast implements ShouldQueue

use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

* Create a new job instance.

public function __construct(Podcast $podcast)

* @param AudioProcessor $processor

public function handle(AudioProcessor $processor)

// Process uploaded podcast...

40 có thể là bất kỳ chuỗi nào xác định duy nhất loại công việc bạn muốn xếp hạng giới hạn. Ví dụ: bạn có thể muốn tạo khóa dựa trên tên lớp của công việc và ID của các mô hình Eloquent mà nó hoạt động trên đó

Ngoài ra, bạn có thể chỉ định số lượng công nhân tối đa có thể đồng thời xử lý một công việc nhất định. Điều này có thể hữu ích khi một công việc trong hàng đợi đang sửa đổi một tài nguyên mà mỗi lần chỉ nên sửa đổi một công việc. Ví dụ: sử dụng phương pháp

use Illuminate\Bus\Queueable;

use Illuminate\Queue\SerializesModels;

use Illuminate\Queue\InteractsWithQueue;

use Illuminate\Contracts\Queue\ShouldQueue;

use Illuminate\Foundation\Bus\Dispatchable;

class ProcessPodcast implements ShouldQueue

use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

* Create a new job instance.

public function __construct(Podcast $podcast)

* @param AudioProcessor $processor

public function handle(AudioProcessor $processor)

// Process uploaded podcast...

41, bạn có thể giới hạn các công việc của một loại nhất định chỉ được xử lý bởi một công nhân tại một thời điểm

php artisan queue:work --queue=high,default

6

{tip} Khi sử dụng giới hạn tốc độ, có thể khó xác định số lần thử mà công việc của bạn cần để chạy thành công. Do đó, sẽ rất hữu ích khi kết hợp giới hạn tỷ lệ với

Xử lý lỗi

Nếu một ngoại lệ được đưa ra trong khi công việc đang được xử lý, công việc sẽ tự động được giải phóng trở lại hàng đợi để có thể thử lại. Công việc sẽ tiếp tục được giải phóng cho đến khi nó được thử với số lần tối đa mà ứng dụng của bạn cho phép. Số lần thử tối đa được xác định bởi công tắc

use Illuminate\Bus\Queueable;

use Illuminate\Queue\SerializesModels;

use Illuminate\Queue\InteractsWithQueue;

use Illuminate\Contracts\Queue\ShouldQueue;

use Illuminate\Foundation\Bus\Dispatchable;

class ProcessPodcast implements ShouldQueue

use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

* Create a new job instance.

public function __construct(Podcast $podcast)

* @param AudioProcessor $processor

public function handle(AudioProcessor $processor)

// Process uploaded podcast...

23 được sử dụng trên lệnh Artisan

use Illuminate\Bus\Queueable;

use Illuminate\Queue\SerializesModels;

use Illuminate\Queue\InteractsWithQueue;

use Illuminate\Contracts\Queue\ShouldQueue;

use Illuminate\Foundation\Bus\Dispatchable;

class ProcessPodcast implements ShouldQueue

use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

* Create a new job instance.

public function __construct(Podcast $podcast)

* @param AudioProcessor $processor

public function handle(AudioProcessor $processor)

// Process uploaded podcast...

43. Ngoài ra, số lần thử tối đa có thể được xác định trên chính lớp công việc. Thông tin thêm về cách chạy queue worker

Chạy công nhân xếp hàng

Laravel bao gồm queue worker sẽ xử lý các công việc mới khi chúng được đẩy vào hàng đợi. Bạn có thể chạy worker bằng lệnh

use Illuminate\Bus\Queueable;

use Illuminate\Queue\SerializesModels;

use Illuminate\Queue\InteractsWithQueue;

use Illuminate\Contracts\Queue\ShouldQueue;

use Illuminate\Foundation\Bus\Dispatchable;

class ProcessPodcast implements ShouldQueue

use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

* Create a new job instance.

public function __construct(Podcast $podcast)

* @param AudioProcessor $processor

public function handle(AudioProcessor $processor)

// Process uploaded podcast...

43 Artisan. Lưu ý rằng một khi lệnh

use Illuminate\Bus\Queueable;

use Illuminate\Queue\SerializesModels;

use Illuminate\Queue\InteractsWithQueue;

use Illuminate\Contracts\Queue\ShouldQueue;

use Illuminate\Foundation\Bus\Dispatchable;

class ProcessPodcast implements ShouldQueue

use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

* Create a new job instance.

public function __construct(Podcast $podcast)

* @param AudioProcessor $processor

public function handle(AudioProcessor $processor)

// Process uploaded podcast...

43 đã bắt đầu, nó sẽ tiếp tục chạy cho đến khi bị dừng thủ công hoặc bạn đóng thiết bị đầu cuối của mình

{tip} Để giữ cho quy trình

use Illuminate\Bus\Queueable;

use Illuminate\Queue\SerializesModels;

use Illuminate\Queue\InteractsWithQueue;

use Illuminate\Contracts\Queue\ShouldQueue;

use Illuminate\Foundation\Bus\Dispatchable;

class ProcessPodcast implements ShouldQueue

use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

* Create a new job instance.

public function __construct(Podcast $podcast)

* @param AudioProcessor $processor

public function handle(AudioProcessor $processor)

// Process uploaded podcast...

43 chạy vĩnh viễn trong nền, bạn nên sử dụng trình giám sát quy trình để đảm bảo rằng nhân viên xếp hàng không ngừng chạy

Hãy nhớ rằng, nhân viên xếp hàng là các quy trình tồn tại lâu dài và lưu trữ trạng thái ứng dụng đã khởi động trong bộ nhớ. Do đó, họ sẽ không nhận thấy những thay đổi trong cơ sở mã của bạn sau khi chúng được bắt đầu. Vì vậy, trong quá trình triển khai của bạn, hãy đảm bảo

Xử lý một công việc duy nhất

Tùy chọn

use Illuminate\Bus\Queueable;

use Illuminate\Queue\SerializesModels;

use Illuminate\Queue\InteractsWithQueue;

use Illuminate\Contracts\Queue\ShouldQueue;

use Illuminate\Foundation\Bus\Dispatchable;

class ProcessPodcast implements ShouldQueue

use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

* Create a new job instance.

public function __construct(Podcast $podcast)

* @param AudioProcessor $processor

public function handle(AudioProcessor $processor)

// Process uploaded podcast...

47 có thể được sử dụng để hướng dẫn nhân viên chỉ xử lý một công việc duy nhất từ ​​hàng đợi

php artisan queue:work --queue=high,default

7

Chỉ định Kết nối & Hàng đợi

Bạn cũng có thể chỉ định kết nối hàng đợi nào mà nhân viên sẽ sử dụng. Tên kết nối được chuyển đến lệnh

use Illuminate\Bus\Queueable;

use Illuminate\Queue\SerializesModels;

use Illuminate\Queue\InteractsWithQueue;

use Illuminate\Contracts\Queue\ShouldQueue;

use Illuminate\Foundation\Bus\Dispatchable;

class ProcessPodcast implements ShouldQueue

use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

* Create a new job instance.

public function __construct(Podcast $podcast)

* @param AudioProcessor $processor

public function handle(AudioProcessor $processor)

// Process uploaded podcast...

48 phải tương ứng với một trong các kết nối được xác định trong tệp cấu hình

use Illuminate\Bus\Queueable;

use Illuminate\Queue\SerializesModels;

use Illuminate\Queue\InteractsWithQueue;

use Illuminate\Contracts\Queue\ShouldQueue;

use Illuminate\Foundation\Bus\Dispatchable;

class ProcessPodcast implements ShouldQueue

use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

* Create a new job instance.

public function __construct(Podcast $podcast)

* @param AudioProcessor $processor

public function handle(AudioProcessor $processor)

// Process uploaded podcast...

3 của bạn

php artisan queue:work --queue=high,default

8

Bạn có thể tùy chỉnh trình xử lý hàng đợi của mình hơn nữa bằng cách chỉ xử lý các hàng đợi cụ thể cho một kết nối nhất định. Ví dụ: nếu tất cả email của bạn được xử lý trong hàng đợi

use Illuminate\Bus\Queueable;

use Illuminate\Queue\SerializesModels;

use Illuminate\Queue\InteractsWithQueue;

use Illuminate\Contracts\Queue\ShouldQueue;

use Illuminate\Foundation\Bus\Dispatchable;

class ProcessPodcast implements ShouldQueue

use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

* Create a new job instance.

public function __construct(Podcast $podcast)

* @param AudioProcessor $processor

public function handle(AudioProcessor $processor)

// Process uploaded podcast...

60 trên kết nối hàng đợi

namespace App\Http\Controllers;

use App\Jobs\ProcessPodcast;

use Illuminate\Http\Request;

use App\Http\Controllers\Controller;

class PodcastController extends Controller

public function store(Request $request)

ProcessPodcast::dispatch($podcast);

4 của bạn, bạn có thể đưa ra lệnh sau để bắt đầu một nhân viên chỉ xử lý hàng đợi đó

php artisan queue:work --queue=high,default

9

Cân nhắc tài nguyên

Daemon queue worker không "khởi động lại" khung trước khi xử lý từng công việc. Do đó, bạn nên giải phóng mọi tài nguyên nặng sau mỗi công việc hoàn thành. Ví dụ: nếu bạn đang thực hiện thao tác hình ảnh với thư viện GD, bạn nên giải phóng bộ nhớ bằng

use Illuminate\Bus\Queueable;

use Illuminate\Queue\SerializesModels;

use Illuminate\Queue\InteractsWithQueue;

use Illuminate\Contracts\Queue\ShouldQueue;

use Illuminate\Foundation\Bus\Dispatchable;

class ProcessPodcast implements ShouldQueue

use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

* Create a new job instance.

public function __construct(Podcast $podcast)

* @param AudioProcessor $processor

public function handle(AudioProcessor $processor)

// Process uploaded podcast...

62 khi hoàn tất

Ưu tiên hàng đợi

Đôi khi bạn có thể muốn ưu tiên cách hàng đợi của mình được xử lý. Ví dụ: trong

use Illuminate\Bus\Queueable;

use Illuminate\Queue\SerializesModels;

use Illuminate\Queue\InteractsWithQueue;

use Illuminate\Contracts\Queue\ShouldQueue;

use Illuminate\Foundation\Bus\Dispatchable;

class ProcessPodcast implements ShouldQueue

use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

* Create a new job instance.

public function __construct(Podcast $podcast)

* @param AudioProcessor $processor

public function handle(AudioProcessor $processor)

// Process uploaded podcast...

3 của bạn, bạn có thể đặt

use Illuminate\Bus\Queueable;

use Illuminate\Queue\SerializesModels;

use Illuminate\Queue\InteractsWithQueue;

use Illuminate\Contracts\Queue\ShouldQueue;

use Illuminate\Foundation\Bus\Dispatchable;

class ProcessPodcast implements ShouldQueue

use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

* Create a new job instance.

public function __construct(Podcast $podcast)

* @param AudioProcessor $processor

public function handle(AudioProcessor $processor)

// Process uploaded podcast...

7 mặc định cho kết nối

namespace App\Http\Controllers;

use App\Jobs\ProcessPodcast;

use Illuminate\Http\Request;

use App\Http\Controllers\Controller;

class PodcastController extends Controller

public function store(Request $request)

ProcessPodcast::dispatch($podcast);

4 của mình thành

use Illuminate\Bus\Queueable;

use Illuminate\Queue\SerializesModels;

use Illuminate\Queue\InteractsWithQueue;

use Illuminate\Contracts\Queue\ShouldQueue;

use Illuminate\Foundation\Bus\Dispatchable;

class ProcessPodcast implements ShouldQueue

use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

* Create a new job instance.

public function __construct(Podcast $podcast)

* @param AudioProcessor $processor

public function handle(AudioProcessor $processor)

// Process uploaded podcast...

66. Tuy nhiên, đôi khi bạn có thể muốn đẩy một công việc vào hàng đợi ưu tiên

namespace App\Http\Controllers;

use App\Jobs\ProcessPodcast;

use Illuminate\Http\Request;

use App\Http\Controllers\Controller;

class PodcastController extends Controller

public function store(Request $request)

ProcessPodcast::dispatch($podcast);

0 như vậy

use Illuminate\Bus\Queueable;

use Illuminate\Queue\SerializesModels;

use Illuminate\Queue\InteractsWithQueue;

use Illuminate\Contracts\Queue\ShouldQueue;

use Illuminate\Foundation\Bus\Dispatchable;

class ProcessPodcast implements ShouldQueue

use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

* Create a new job instance.

public function __construct(Podcast $podcast)

* @param AudioProcessor $processor

public function handle(AudioProcessor $processor)

// Process uploaded podcast...

80

Để bắt đầu một worker xác minh rằng tất cả các công việc trong hàng đợi của

namespace App\Http\Controllers;

use App\Jobs\ProcessPodcast;

use Illuminate\Http\Request;

use App\Http\Controllers\Controller;

class PodcastController extends Controller

public function store(Request $request)

ProcessPodcast::dispatch($podcast);

0 đã được xử lý trước khi tiếp tục với bất kỳ công việc nào trên hàng đợi của

use Illuminate\Bus\Queueable;

use Illuminate\Queue\SerializesModels;

use Illuminate\Queue\InteractsWithQueue;

use Illuminate\Contracts\Queue\ShouldQueue;

use Illuminate\Foundation\Bus\Dispatchable;

class ProcessPodcast implements ShouldQueue

use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

* Create a new job instance.

public function __construct(Podcast $podcast)

* @param AudioProcessor $processor

public function handle(AudioProcessor $processor)

// Process uploaded podcast...

66, hãy chuyển một danh sách các tên hàng đợi được phân tách bằng dấu phẩy cho lệnh

use Illuminate\Bus\Queueable;

use Illuminate\Queue\SerializesModels;

use Illuminate\Queue\InteractsWithQueue;

use Illuminate\Contracts\Queue\ShouldQueue;

use Illuminate\Foundation\Bus\Dispatchable;

class ProcessPodcast implements ShouldQueue

use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

* Create a new job instance.

public function __construct(Podcast $podcast)

* @param AudioProcessor $processor

public function handle(AudioProcessor $processor)

// Process uploaded podcast...

48

use Illuminate\Bus\Queueable;

use Illuminate\Queue\SerializesModels;

use Illuminate\Queue\InteractsWithQueue;

use Illuminate\Contracts\Queue\ShouldQueue;

use Illuminate\Foundation\Bus\Dispatchable;

class ProcessPodcast implements ShouldQueue

use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

* Create a new job instance.

public function __construct(Podcast $podcast)

* @param AudioProcessor $processor

public function handle(AudioProcessor $processor)

// Process uploaded podcast...

81

Công nhân xếp hàng & triển khai

Vì trình xử lý hàng đợi là các quy trình tồn tại lâu dài, chúng sẽ không nhận các thay đổi đối với mã của bạn mà không được khởi động lại. Vì vậy, cách đơn giản nhất để triển khai một ứng dụng bằng queue worker là khởi động lại các worker trong quá trình triển khai của bạn. Bạn có thể khởi động lại tất cả các công nhân một cách duyên dáng bằng cách đưa ra lệnh

use Illuminate\Bus\Queueable;

use Illuminate\Queue\SerializesModels;

use Illuminate\Queue\InteractsWithQueue;

use Illuminate\Contracts\Queue\ShouldQueue;

use Illuminate\Foundation\Bus\Dispatchable;

class ProcessPodcast implements ShouldQueue

use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

* Create a new job instance.

public function __construct(Podcast $podcast)

* @param AudioProcessor $processor

public function handle(AudioProcessor $processor)

// Process uploaded podcast...

91

Lệnh này sẽ hướng dẫn tất cả nhân viên xếp hàng "chết" một cách duyên dáng sau khi họ xử lý xong công việc hiện tại để không có công việc hiện có nào bị mất. Vì nhân viên xếp hàng sẽ chết khi lệnh

use Illuminate\Bus\Queueable;

use Illuminate\Queue\SerializesModels;

use Illuminate\Queue\InteractsWithQueue;

use Illuminate\Contracts\Queue\ShouldQueue;

use Illuminate\Foundation\Bus\Dispatchable;

class ProcessPodcast implements ShouldQueue

use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

* Create a new job instance.

public function __construct(Podcast $podcast)

* @param AudioProcessor $processor

public function handle(AudioProcessor $processor)

// Process uploaded podcast...

91 được thực thi, bạn nên chạy trình quản lý quy trình, chẳng hạn như để tự động khởi động lại nhân viên xếp hàng

{tip} Hàng đợi sử dụng bộ đệm để lưu các tín hiệu khởi động lại, vì vậy bạn nên xác minh trình điều khiển bộ đệm được định cấu hình đúng cho ứng dụng của mình trước khi sử dụng tính năng này

Hết hạn Công việc & Thời gian chờ

hết hạn công việc

Trong tệp cấu hình

use Illuminate\Bus\Queueable;

use Illuminate\Queue\SerializesModels;

use Illuminate\Queue\InteractsWithQueue;

use Illuminate\Contracts\Queue\ShouldQueue;

use Illuminate\Foundation\Bus\Dispatchable;

class ProcessPodcast implements ShouldQueue

use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

* Create a new job instance.

public function __construct(Podcast $podcast)

* @param AudioProcessor $processor

public function handle(AudioProcessor $processor)

// Process uploaded podcast...

3 của bạn, mỗi kết nối hàng đợi xác định một tùy chọn

use Illuminate\Bus\Queueable;

use Illuminate\Queue\SerializesModels;

use Illuminate\Queue\InteractsWithQueue;

use Illuminate\Contracts\Queue\ShouldQueue;

use Illuminate\Foundation\Bus\Dispatchable;

class ProcessPodcast implements ShouldQueue

use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

* Create a new job instance.

public function __construct(Podcast $podcast)

* @param AudioProcessor $processor

public function handle(AudioProcessor $processor)

// Process uploaded podcast...

94. Tùy chọn này chỉ định số giây kết nối hàng đợi sẽ đợi trước khi thử lại một công việc đang được xử lý. Ví dụ: nếu giá trị của

use Illuminate\Bus\Queueable;

use Illuminate\Queue\SerializesModels;

use Illuminate\Queue\InteractsWithQueue;

use Illuminate\Contracts\Queue\ShouldQueue;

use Illuminate\Foundation\Bus\Dispatchable;

class ProcessPodcast implements ShouldQueue

use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

* Create a new job instance.

public function __construct(Podcast $podcast)

* @param AudioProcessor $processor

public function handle(AudioProcessor $processor)

// Process uploaded podcast...

94 được đặt thành

use Illuminate\Bus\Queueable;

use Illuminate\Queue\SerializesModels;

use Illuminate\Queue\InteractsWithQueue;

use Illuminate\Contracts\Queue\ShouldQueue;

use Illuminate\Foundation\Bus\Dispatchable;

class ProcessPodcast implements ShouldQueue

use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

* Create a new job instance.

public function __construct(Podcast $podcast)

* @param AudioProcessor $processor

public function handle(AudioProcessor $processor)

// Process uploaded podcast...

96, công việc sẽ được giải phóng trở lại hàng đợi nếu nó đã được xử lý trong 90 giây mà không bị xóa. Thông thường, bạn nên đặt giá trị

use Illuminate\Bus\Queueable;

use Illuminate\Queue\SerializesModels;

use Illuminate\Queue\InteractsWithQueue;

use Illuminate\Contracts\Queue\ShouldQueue;

use Illuminate\Foundation\Bus\Dispatchable;

class ProcessPodcast implements ShouldQueue

use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

* Create a new job instance.

public function __construct(Podcast $podcast)

* @param AudioProcessor $processor

public function handle(AudioProcessor $processor)

// Process uploaded podcast...

94 thành số giây tối đa mà công việc của bạn cần một cách hợp lý để hoàn tất quá trình xử lý

{note} Kết nối hàng đợi duy nhất không chứa giá trị

use Illuminate\Bus\Queueable;

use Illuminate\Queue\SerializesModels;

use Illuminate\Queue\InteractsWithQueue;

use Illuminate\Contracts\Queue\ShouldQueue;

use Illuminate\Foundation\Bus\Dispatchable;

class ProcessPodcast implements ShouldQueue

use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

* Create a new job instance.

public function __construct(Podcast $podcast)

* @param AudioProcessor $processor

public function handle(AudioProcessor $processor)

// Process uploaded podcast...

94 là Amazon SQS. SQS sẽ thử lại công việc dựa trên Thời gian chờ hiển thị mặc định được quản lý trong bảng điều khiển AWS

Thời gian chờ của công nhân

Lệnh

use Illuminate\Bus\Queueable;

use Illuminate\Queue\SerializesModels;

use Illuminate\Queue\InteractsWithQueue;

use Illuminate\Contracts\Queue\ShouldQueue;

use Illuminate\Foundation\Bus\Dispatchable;

class ProcessPodcast implements ShouldQueue

use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

* Create a new job instance.

public function __construct(Podcast $podcast)

* @param AudioProcessor $processor

public function handle(AudioProcessor $processor)

// Process uploaded podcast...

43 Artisan hiển thị tùy chọn

use Illuminate\Bus\Queueable;

use Illuminate\Queue\SerializesModels;

use Illuminate\Queue\InteractsWithQueue;

use Illuminate\Contracts\Queue\ShouldQueue;

use Illuminate\Foundation\Bus\Dispatchable;

class ProcessPodcast implements ShouldQueue

use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

* Create a new job instance.

public function __construct(Podcast $podcast)

* @param AudioProcessor $processor

public function handle(AudioProcessor $processor)

// Process uploaded podcast...

28. Tùy chọn

use Illuminate\Bus\Queueable;

use Illuminate\Queue\SerializesModels;

use Illuminate\Queue\InteractsWithQueue;

use Illuminate\Contracts\Queue\ShouldQueue;

use Illuminate\Foundation\Bus\Dispatchable;

class ProcessPodcast implements ShouldQueue

use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

* Create a new job instance.

public function __construct(Podcast $podcast)

* @param AudioProcessor $processor

public function handle(AudioProcessor $processor)

// Process uploaded podcast...

28 chỉ định khoảng thời gian Laravel queue master process sẽ đợi trước khi kill một queue worker đang xử lý một job. Đôi khi, quy trình hàng đợi con có thể bị "đóng băng" vì nhiều lý do, chẳng hạn như lệnh gọi HTTP bên ngoài không phản hồi. Tùy chọn ________ 328 loại bỏ các quy trình bị đóng băng đã vượt quá giới hạn thời gian đã chỉ định

use Illuminate\Bus\Queueable;

use Illuminate\Queue\SerializesModels;

use Illuminate\Queue\InteractsWithQueue;

use Illuminate\Contracts\Queue\ShouldQueue;

use Illuminate\Foundation\Bus\Dispatchable;

class ProcessPodcast implements ShouldQueue

use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

* Create a new job instance.

public function __construct(Podcast $podcast)

* @param AudioProcessor $processor

public function handle(AudioProcessor $processor)

// Process uploaded podcast...

82

Tùy chọn cấu hình

use Illuminate\Bus\Queueable;

use Illuminate\Queue\SerializesModels;

use Illuminate\Queue\InteractsWithQueue;

use Illuminate\Contracts\Queue\ShouldQueue;

use Illuminate\Foundation\Bus\Dispatchable;

class ProcessPodcast implements ShouldQueue

use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

* Create a new job instance.

public function __construct(Podcast $podcast)

* @param AudioProcessor $processor

public function handle(AudioProcessor $processor)

// Process uploaded podcast...

94 và tùy chọn

use Illuminate\Bus\Queueable;

use Illuminate\Queue\SerializesModels;

use Illuminate\Queue\InteractsWithQueue;

use Illuminate\Contracts\Queue\ShouldQueue;

use Illuminate\Foundation\Bus\Dispatchable;

class ProcessPodcast implements ShouldQueue

use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

* Create a new job instance.

public function __construct(Podcast $podcast)

* @param AudioProcessor $processor

public function handle(AudioProcessor $processor)

// Process uploaded podcast...

28 CLI khác nhau, nhưng hoạt động cùng nhau để đảm bảo rằng các công việc không bị mất và các công việc chỉ được xử lý thành công một lần

{note} Giá trị

use Illuminate\Bus\Queueable;

use Illuminate\Queue\SerializesModels;

use Illuminate\Queue\InteractsWithQueue;

use Illuminate\Contracts\Queue\ShouldQueue;

use Illuminate\Foundation\Bus\Dispatchable;

class ProcessPodcast implements ShouldQueue

use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

* Create a new job instance.

public function __construct(Podcast $podcast)

* @param AudioProcessor $processor

public function handle(AudioProcessor $processor)

// Process uploaded podcast...

28 phải luôn ngắn hơn giá trị cấu hình

use Illuminate\Bus\Queueable;

use Illuminate\Queue\SerializesModels;

use Illuminate\Queue\InteractsWithQueue;

use Illuminate\Contracts\Queue\ShouldQueue;

use Illuminate\Foundation\Bus\Dispatchable;

class ProcessPodcast implements ShouldQueue

use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

* Create a new job instance.

public function __construct(Podcast $podcast)

* @param AudioProcessor $processor

public function handle(AudioProcessor $processor)

// Process uploaded podcast...

94 của bạn ít nhất vài giây. Điều này sẽ đảm bảo rằng một công nhân xử lý một công việc nhất định luôn bị giết trước khi công việc được thử lại. Nếu tùy chọn

use Illuminate\Bus\Queueable;

use Illuminate\Queue\SerializesModels;

use Illuminate\Queue\InteractsWithQueue;

use Illuminate\Contracts\Queue\ShouldQueue;

use Illuminate\Foundation\Bus\Dispatchable;

class ProcessPodcast implements ShouldQueue

use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

* Create a new job instance.

public function __construct(Podcast $podcast)

* @param AudioProcessor $processor

public function handle(AudioProcessor $processor)

// Process uploaded podcast...

28 của bạn dài hơn giá trị cấu hình

use Illuminate\Bus\Queueable;

use Illuminate\Queue\SerializesModels;

use Illuminate\Queue\InteractsWithQueue;

use Illuminate\Contracts\Queue\ShouldQueue;

use Illuminate\Foundation\Bus\Dispatchable;

class ProcessPodcast implements ShouldQueue

use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

* Create a new job instance.

public function __construct(Podcast $podcast)

* @param AudioProcessor $processor

public function handle(AudioProcessor $processor)

// Process uploaded podcast...

94, công việc của bạn có thể được xử lý hai lần

Thời gian ngủ của công nhân

Khi các công việc có sẵn trên hàng đợi, worker sẽ tiếp tục xử lý các công việc mà không có độ trễ giữa các công việc đó. Tuy nhiên, tùy chọn

php artisan queue:work --queue=high,default

09 xác định thời gian công nhân sẽ "ngủ" nếu không có công việc mới. Trong khi ngủ, worker sẽ không xử lý bất kỳ công việc mới nào - các công việc sẽ được xử lý sau khi worker thức dậy lần nữa

use Illuminate\Bus\Queueable;

use Illuminate\Queue\SerializesModels;

use Illuminate\Queue\InteractsWithQueue;

use Illuminate\Contracts\Queue\ShouldQueue;

use Illuminate\Foundation\Bus\Dispatchable;

class ProcessPodcast implements ShouldQueue

use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

* Create a new job instance.

public function __construct(Podcast $podcast)

* @param AudioProcessor $processor

public function handle(AudioProcessor $processor)

// Process uploaded podcast...

83

Cấu hình giám sát

Giám sát cài đặt

Người giám sát là người giám sát quy trình cho hệ điều hành Linux và sẽ tự động khởi động lại quy trình

use Illuminate\Bus\Queueable;

use Illuminate\Queue\SerializesModels;

use Illuminate\Queue\InteractsWithQueue;

use Illuminate\Contracts\Queue\ShouldQueue;

use Illuminate\Foundation\Bus\Dispatchable;

class ProcessPodcast implements ShouldQueue

use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

* Create a new job instance.

public function __construct(Podcast $podcast)

* @param AudioProcessor $processor

public function handle(AudioProcessor $processor)

// Process uploaded podcast...

43 của bạn nếu nó không thành công. Để cài đặt Trình giám sát trên Ubuntu, bạn có thể sử dụng lệnh sau

use Illuminate\Bus\Queueable;

use Illuminate\Queue\SerializesModels;

use Illuminate\Queue\InteractsWithQueue;

use Illuminate\Contracts\Queue\ShouldQueue;

use Illuminate\Foundation\Bus\Dispatchable;

class ProcessPodcast implements ShouldQueue

use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

* Create a new job instance.

public function __construct(Podcast $podcast)

* @param AudioProcessor $processor

public function handle(AudioProcessor $processor)

// Process uploaded podcast...

84

{tip} Nếu việc tự định cấu hình Trình giám sát nghe có vẻ quá sức, hãy cân nhắc sử dụng Laravel Forge, phần mềm này sẽ tự động cài đặt và định cấu hình Trình giám sát cho các dự án Laravel của bạn

Cấu hình giám sát viên

Các tệp cấu hình giám sát thường được lưu trữ trong thư mục

php artisan queue:work --queue=high,default

11. Trong thư mục này, bạn có thể tạo bất kỳ số lượng tệp cấu hình nào hướng dẫn người giám sát cách giám sát các quy trình của bạn. Ví dụ: hãy tạo tệp

php artisan queue:work --queue=high,default

12 bắt đầu và theo dõi quy trình

use Illuminate\Bus\Queueable;

use Illuminate\Queue\SerializesModels;

use Illuminate\Queue\InteractsWithQueue;

use Illuminate\Contracts\Queue\ShouldQueue;

use Illuminate\Foundation\Bus\Dispatchable;

class ProcessPodcast implements ShouldQueue

use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

* Create a new job instance.

public function __construct(Podcast $podcast)

* @param AudioProcessor $processor

public function handle(AudioProcessor $processor)

// Process uploaded podcast...

43

use Illuminate\Bus\Queueable;

use Illuminate\Queue\SerializesModels;

use Illuminate\Queue\InteractsWithQueue;

use Illuminate\Contracts\Queue\ShouldQueue;

use Illuminate\Foundation\Bus\Dispatchable;

class ProcessPodcast implements ShouldQueue

use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

* Create a new job instance.

public function __construct(Podcast $podcast)

* @param AudioProcessor $processor

public function handle(AudioProcessor $processor)

// Process uploaded podcast...

85

Trong ví dụ này, chỉ thị

php artisan queue:work --queue=high,default

14 sẽ hướng dẫn Người giám sát chạy 8 quy trình

use Illuminate\Bus\Queueable;

use Illuminate\Queue\SerializesModels;

use Illuminate\Queue\InteractsWithQueue;

use Illuminate\Contracts\Queue\ShouldQueue;

use Illuminate\Foundation\Bus\Dispatchable;

class ProcessPodcast implements ShouldQueue

use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

* Create a new job instance.

public function __construct(Podcast $podcast)

* @param AudioProcessor $processor

public function handle(AudioProcessor $processor)

// Process uploaded podcast...

43 và giám sát tất cả chúng, tự động khởi động lại chúng nếu chúng không thành công. Tất nhiên, bạn nên thay đổi phần

php artisan queue:work --queue=high,default

16 của chỉ thị

php artisan queue:work --queue=high,default

17 để phản ánh kết nối hàng đợi mong muốn của bạn

Người giám sát bắt đầu

Khi tệp cấu hình đã được tạo, bạn có thể cập nhật cấu hình Người giám sát và bắt đầu các quy trình bằng cách sử dụng các lệnh sau

use Illuminate\Bus\Queueable;

use Illuminate\Queue\SerializesModels;

use Illuminate\Queue\InteractsWithQueue;

use Illuminate\Contracts\Queue\ShouldQueue;

use Illuminate\Foundation\Bus\Dispatchable;

class ProcessPodcast implements ShouldQueue

use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

* Create a new job instance.

public function __construct(Podcast $podcast)

* @param AudioProcessor $processor

public function handle(AudioProcessor $processor)

// Process uploaded podcast...

86

Để biết thêm thông tin về Người giám sát, hãy tham khảo tài liệu Người giám sát

Xử lý công việc thất bại

Đôi khi công việc xếp hàng đợi của bạn sẽ thất bại. Đừng lo lắng, không phải lúc nào mọi thứ cũng diễn ra theo kế hoạch. Laravel bao gồm một cách thuận tiện để chỉ định số lần tối đa một công việc nên được thực hiện. Sau khi một công việc vượt quá số lần thử này, nó sẽ được chèn vào bảng cơ sở dữ liệu

php artisan queue:work --queue=high,default

18. Để tạo di chuyển cho bảng

php artisan queue:work --queue=high,default

18, bạn có thể sử dụng lệnh

php artisan queue:work --queue=high,default

20

use Illuminate\Bus\Queueable;

use Illuminate\Queue\SerializesModels;

use Illuminate\Queue\InteractsWithQueue;

use Illuminate\Contracts\Queue\ShouldQueue;

use Illuminate\Foundation\Bus\Dispatchable;

class ProcessPodcast implements ShouldQueue

use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

* Create a new job instance.

public function __construct(Podcast $podcast)

* @param AudioProcessor $processor

public function handle(AudioProcessor $processor)

// Process uploaded podcast...

87

Sau đó, khi chạy , bạn nên chỉ định số lần tối đa một công việc sẽ được thực hiện bằng cách sử dụng công tắc

use Illuminate\Bus\Queueable;

use Illuminate\Queue\SerializesModels;

use Illuminate\Queue\InteractsWithQueue;

use Illuminate\Contracts\Queue\ShouldQueue;

use Illuminate\Foundation\Bus\Dispatchable;

class ProcessPodcast implements ShouldQueue

use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

* Create a new job instance.

public function __construct(Podcast $podcast)

* @param AudioProcessor $processor

public function handle(AudioProcessor $processor)

// Process uploaded podcast...

23 trên lệnh

use Illuminate\Bus\Queueable;

use Illuminate\Queue\SerializesModels;

use Illuminate\Queue\InteractsWithQueue;

use Illuminate\Contracts\Queue\ShouldQueue;

use Illuminate\Foundation\Bus\Dispatchable;

class ProcessPodcast implements ShouldQueue

use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

* Create a new job instance.

public function __construct(Podcast $podcast)

* @param AudioProcessor $processor

public function handle(AudioProcessor $processor)

// Process uploaded podcast...

43. Nếu bạn không chỉ định giá trị cho tùy chọn

use Illuminate\Bus\Queueable;

use Illuminate\Queue\SerializesModels;

use Illuminate\Queue\InteractsWithQueue;

use Illuminate\Contracts\Queue\ShouldQueue;

use Illuminate\Foundation\Bus\Dispatchable;

class ProcessPodcast implements ShouldQueue

use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

* Create a new job instance.

public function __construct(Podcast $podcast)

* @param AudioProcessor $processor

public function handle(AudioProcessor $processor)

// Process uploaded podcast...

23, các công việc sẽ được thực hiện vô thời hạn

use Illuminate\Bus\Queueable;

use Illuminate\Queue\SerializesModels;

use Illuminate\Queue\InteractsWithQueue;

use Illuminate\Contracts\Queue\ShouldQueue;

use Illuminate\Foundation\Bus\Dispatchable;

class ProcessPodcast implements ShouldQueue

use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

* Create a new job instance.

public function __construct(Podcast $podcast)

* @param AudioProcessor $processor

public function handle(AudioProcessor $processor)

// Process uploaded podcast...

88

Dọn dẹp sau khi thất bại công việc

Bạn có thể xác định một phương thức

php artisan queue:work --queue=high,default

24 trực tiếp trên lớp công việc của mình, cho phép bạn thực hiện dọn dẹp công việc cụ thể khi xảy ra lỗi. Đây là vị trí hoàn hảo để gửi cảnh báo cho người dùng của bạn hoặc hoàn nguyên bất kỳ hành động nào được thực hiện bởi công việc.

php artisan queue:work --queue=high,default

25 khiến công việc thất bại sẽ được chuyển sang phương thức

php artisan queue:work --queue=high,default

24

use Illuminate\Bus\Queueable;

use Illuminate\Queue\SerializesModels;

use Illuminate\Queue\InteractsWithQueue;

use Illuminate\Contracts\Queue\ShouldQueue;

use Illuminate\Foundation\Bus\Dispatchable;

class ProcessPodcast implements ShouldQueue

use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

* Create a new job instance.

public function __construct(Podcast $podcast)

* @param AudioProcessor $processor

public function handle(AudioProcessor $processor)

// Process uploaded podcast...

89

Sự kiện Công việc Thất bại

Nếu bạn muốn đăng ký một sự kiện sẽ được gọi khi một công việc thất bại, bạn có thể sử dụng phương pháp

php artisan queue:work --queue=high,default

27. Sự kiện này là một cơ hội tuyệt vời để thông báo cho nhóm của bạn qua email hoặc HipChat. Ví dụ: chúng tôi có thể đính kèm một cuộc gọi lại cho sự kiện này từ

php artisan queue:work --queue=high,default

28 được bao gồm trong Laravel

use Illuminate\Bus\Queueable;

use Illuminate\Queue\SerializesModels;

use Illuminate\Queue\InteractsWithQueue;

use Illuminate\Contracts\Queue\ShouldQueue;

use Illuminate\Foundation\Bus\Dispatchable;

class ProcessPodcast implements ShouldQueue

use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

* Create a new job instance.

public function __construct(Podcast $podcast)

* @param AudioProcessor $processor

public function handle(AudioProcessor $processor)

// Process uploaded podcast...

0

Thử lại công việc thất bại

Để xem tất cả các công việc thất bại đã được chèn vào bảng cơ sở dữ liệu

php artisan queue:work --queue=high,default

18 của bạn, bạn có thể sử dụng lệnh Artisan

php artisan queue:work --queue=high,default

30

Lệnh

php artisan queue:work --queue=high,default

30 sẽ liệt kê ID công việc, kết nối, hàng đợi và thời gian lỗi. ID công việc có thể được sử dụng để thử lại công việc không thành công. Chẳng hạn, để thử lại một công việc không thành công có ID là

php artisan queue:work --queue=high,default

32, hãy đưa ra lệnh sau

Để thử lại tất cả các công việc không thành công của bạn, hãy thực hiện lệnh

php artisan queue:work --queue=high,default

33 và chuyển

php artisan queue:work --queue=high,default

34 làm ID

Nếu bạn muốn xóa một công việc không thành công, bạn có thể sử dụng lệnh

php artisan queue:work --queue=high,default

35

Để xóa tất cả các công việc không thành công của bạn, bạn có thể sử dụng lệnh

php artisan queue:work --queue=high,default

36

Sự kiện việc làm

Sử dụng các phương thức

php artisan queue:work --queue=high,default

37 và

php artisan queue:work --queue=high,default

38 trên mặt tiền

php artisan queue:work --queue=high,default

39, bạn có thể chỉ định các cuộc gọi lại sẽ được thực thi trước hoặc sau khi một công việc xếp hàng đợi được xử lý. Các cuộc gọi lại này là cơ hội tuyệt vời để thực hiện ghi nhật ký bổ sung hoặc thống kê gia tăng cho trang tổng quan. Thông thường, bạn nên gọi các phương thức này từ nhà cung cấp dịch vụ. Ví dụ: chúng tôi có thể sử dụng

php artisan queue:work --queue=high,default

28 đi kèm với Laravel

use Illuminate\Bus\Queueable;

use Illuminate\Queue\SerializesModels;

use Illuminate\Queue\InteractsWithQueue;

use Illuminate\Contracts\Queue\ShouldQueue;

use Illuminate\Foundation\Bus\Dispatchable;

class ProcessPodcast implements ShouldQueue

use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

* Create a new job instance.

public function __construct(Podcast $podcast)

* @param AudioProcessor $processor

public function handle(AudioProcessor $processor)

// Process uploaded podcast...

1

Sử dụng phương thức

php artisan queue:work --queue=high,default

41 trên mặt tiền

php artisan queue:work --queue=high,default

39, bạn có thể chỉ định các lệnh gọi lại thực thi trước khi worker cố gắng tìm nạp một công việc từ hàng đợi. Ví dụ: bạn có thể đăng ký Đóng để khôi phục bất kỳ giao dịch nào bị bỏ ngỏ do một công việc không thành công trước đó