繁体   English   中英

Laravel 队列正在处理 state 即使在尝试计数之后

[英]Laravel Queue is in processing state even after giving tries count

尝试使用 Job 发送推送通知

当我运行php artisan queue:workSupervisor合作并继续多次处理单个队列项目

当我尝试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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM