Laravel Jobs-随机任务失败

时间:2020-10-14 16:04:10

标签: php laravel queue jobs

我的主脚本无法正常工作,因此我决定尝试在干净的文件上重现该问题。每分钟我要添加250个任务。任务内容:

<?php

namespace App\Jobs;

use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
use Illuminate\Support\Facades\Log;

class MyJob implements ShouldQueue
{
    use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

    /**
     * The number of times the job may be attempted.
     *
     * @var int
     */
    public $tries = 1;

    /**
     * The maximum number of exceptions to allow before failing.
     *
     * @var int
     */
    public $maxExceptions = 0;

    // /**
    //  * The number of seconds the job can run before timing out.
    //  *
    //  * @var int
    //  */
    // public $timeout = 6;

    /**
     * Server data.
     *
     */
    protected $server;

    /**
     * Create a new job instance.
     *
     * @return void
     */
    public function __construct($array)
    {
        $this->server = null;
        // $this->server = $array;
    }

    /**
     * Execute the job.
     *
     * @return void
     */
    public function handle()
    {
        Log::channel('server')->notice("handle");
        return true;
    }

    public function failed()
    {
        Log::channel('server')->notice("failed");
    }
}

过一会儿,我在数据库中的工作表如下所示: enter image description here

和failed_jobs表: enter image description here

我注意到每分钟大约30-50个任务“卡住”并失败。

我要补充一点,我使用主管。我的配置文件如下所示:

[program:laravel-worker]
process_name=%(program_name)s_%(process_num)02d
command=/usr/bin/php /my_path_to_laravel/artisan queue:work --queue=high,updateServer --timeout=5
autostart=true
autorestart=true
user=root
numprocs=10
redirect_stderr=true
stdout_logfile=/my_path_to_laravel/worker.log
stopwaitsecs=3600

是什么原因导致这些错误?

我的/my_path_to_laravel/worker.log文件: 整个文件看起来像这样:

[2020-10-14 20:56:36][52648] Processing: App\Jobs\MyJob
[2020-10-14 20:56:36][52662] Processing: App\Jobs\MyJob
[2020-10-14 20:56:36][52648] Failed:     App\Jobs\MyJob
[2020-10-14 20:56:36][52652] Processing: App\Jobs\MyJob
[2020-10-14 20:56:36][52652] Failed:     App\Jobs\MyJob
[2020-10-14 20:56:36][52662] Failed:     App\Jobs\MyJob
[2020-10-14 20:56:36][52644] Failed:     App\Jobs\MyJob
[2020-10-14 20:56:36][52673] Processing: App\Jobs\MyJob
[2020-10-14 20:56:36][52677] Processing: App\Jobs\MyJob
[2020-10-14 20:56:36][52663] Processing: App\Jobs\MyJob
[2020-10-14 20:56:36][52679] Processing: App\Jobs\MyJob
[2020-10-14 20:56:36][52677] Failed:     App\Jobs\MyJob
[2020-10-14 20:56:36][52679] Failed:     App\Jobs\MyJob
[2020-10-14 20:56:36][52673] Failed:     App\Jobs\MyJob
[2020-10-14 20:56:36][52663] Failed:     App\Jobs\MyJob
[2020-10-14 20:57:03][53011] Processing: App\Jobs\MyJob
[2020-10-14 20:57:03][53011] Processed:  App\Jobs\MyJob
[2020-10-14 20:57:03][53012] Processing: App\Jobs\MyJob
[2020-10-14 20:57:03][53012] Processed:  App\Jobs\MyJob
[2020-10-14 20:57:03][53013] Processing: App\Jobs\MyJob
[2020-10-14 20:57:03][53014] Processing: App\Jobs\MyJob
[2020-10-14 20:57:03][53013] Processed:  App\Jobs\MyJob
[2020-10-14 20:57:03][53014] Processed:  App\Jobs\MyJob

0 个答案:

没有答案