[英]Laravel Queue is in processing state even after giving tries count
嘗試使用 Job 發送推送通知
當我運行php artisan queue:work
與Supervisor
合作並繼續多次處理單個隊列項目
當我嘗試php artisan queue:listen
時,它給我一個錯誤,它在 60 秒后超時。
The process "'/usr/bin/php7.2' 'artisan' queue:work '' --once --queue='default' --delay=0 --memory=128 --sleep=3 --tries=0" exceeded the timeout of 60 seconds.
到目前為止,我可以讓處理程序在 60 秒內處理所有內容,但我想解決這個問題。
我錯過了什么?
工作正在死去,沒有完成,也沒有失敗
我正在使用Laravel 5.5
我與 Supervisor 一起運行的命令是php artisan queue:work
嘗試運行php artisan queue:restart
並重新啟動主管!
主管工人日志
[2020-08-07 13:26:35] Processing: App\Jobs\SendNotifications
[2020-08-07 13:28:05] Processing: App\Jobs\SendNotifications
[2020-08-07 13:29:36] Processing: App\Jobs\SendNotifications
[2020-08-07 13:31:07] Processing: App\Jobs\SendNotifications
[2020-08-07 13:32:38] Processing: App\Jobs\SendNotifications
[2020-08-07 13:34:08] Processing: App\Jobs\SendNotifications
[2020-08-07 13:35:39] Processing: App\Jobs\SendNotifications
發送通知。php
<?php
namespace App\Jobs;
use Exception;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
use Redis;
class SendNotifications implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
public $payload;
/**
* The number of times the job may be attempted.
*
* @var int
*/
public $tries = 3;
/**
* The number of seconds the job can run before timing out.
*
* @var int
*/
public $timeout = 60;
/**
* Create a new job instance.
*
* @return void
*/
public function __construct($payload)
{
$this->payload = $payload;
}
/**
* Execute the job.
*
* @return void
*/
public function handle()
{
try {
$this->handleNotifications($this->payload);
} catch (Exception $e) {
$this->failed($e);
}
}
/**
* The job failed to process.
*
* @param Exception $exception
* @return void
*/
public function failed(Exception $exception)
{
app('log')->error($exception->getMessage());
}
/**
* Method to compose the mail template
*
* @param json $payloadData
* @return void
*/
public function handleNotifications($payload)
{
..........
}
}
正如@mrhn 在評論中所說
“如果出現任何問題,作業將自動失敗並重試,處理超時錯誤的方法是使作業更快或增加超時。當發生超時時,作業會重試。所以理論上你可以運行 2 個相同的作業如果超時太低。這是一種在作業意外崩潰並且不報告失敗時恢復的方法。
所以我將推薦更改為php artisan queue:work --memory=256 --timeout=600 --tries=3
解決了我的問題。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.