简体   繁体   English

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

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

Trying to send push notification using Job尝试使用 Job 发送推送通知

The worker is not throwing timeout error when I am running php artisan queue:work with Supervisor and keep on processing a Single Queue item for multiple times当我运行php artisan queue:workSupervisor合作并继续多次处理单个队列项目

When I tried php artisan queue:listen it threw me an error that it got a timeout after 60 seconds.当我尝试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.

I can make the handler to process everything within 60 seconds as of now, but I want to fix this.到目前为止,我可以让处理程序在 60 秒内处理所有内容,但我想解决这个问题。

What am I missing?我错过了什么?

Job is dying, not completing and not failing工作正在死去,没有完成,也没有失败

I am using Laravel 5.5我正在使用Laravel 5.5

The command which I am running with Supervisor is php artisan queue:work我与 Supervisor 一起运行的命令是php artisan queue:work

Tried running php artisan queue:restart and restarted Supervisor also!尝试运行php artisan queue:restart并重新启动主管!

Supervisor worker log主管工人日志

[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

SendNotifications.php发送通知。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)
    {
      ..........
    }
}

As @mrhn said in comments正如@mrhn 在评论中所说

"Jobs will automaticly fail and retry if anything goes wrong, the way to handle timeout error is either make the job faster or increase the timeout. When timeouts happens the job is retried. So you can theoretically end up with 2 of the same jobs running if the timeout is to low. It is a way to recover if the job unexpectedly crashes and does not report about it failing." “如果出现任何问题,作业将自动失败并重试,处理超时错误的方法是使作业更快或增加超时。当发生超时时,作业会重试。所以理论上你可以运行 2 个相同的作业如果超时太低。这是一种在作业意外崩溃并且不报告失败时恢复的方法。

So I have changed the commend to php artisan queue:work --memory=256 --timeout=600 --tries=3 which fixed my problem.所以我将推荐更改为php artisan queue:work --memory=256 --timeout=600 --tries=3解决了我的问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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