Laravel symfony 进程超过了 60 秒的超时时间

问题描述

我在 Laravel 中遇到了一个我似乎无法解决的问题。作为我们应用程序的一部分,我们将向队列添加大量作业并使用 queue:work 执行它们。这是使用 Supervisor 设置的,并且运行良好。

我们在使用这个特定命令时遇到了问题(其他命令运行时没有问题)。

在我们的应用程序中,我们使用

调用自定义shell脚本命令

Symfony\Component\Process\Process;

但我一直收到“进程超过 60 秒的超时错误,无论如何。

错误 Symfony\Component\Process\Exception\ProcesstimedOutException:进程“'BIMTool.sh'”超过了 60 秒的超时时间。在 /var/www/app/vendor/symfony/process/Process.PHP:1263

BimTool.sh 脚本启动一系列涉及 Python 和 Anaconda3 的命令,以从 IFC 和点云生成 BIM 模型数据。我什至用“sleep 70”替换了 BimTool.sh 的内容,但运行时仍然出现错误

这是有问题的代码

GenerateModelData.PHP

namespace App\Jobs;

use Illuminate\Bus\Queueable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\dispatchable;
use Illuminate\Support\Facades\Log;
use Symfony\Component\Process\Exception\ProcessFailedException;
use Symfony\Component\Process\Process;
use Carbon\Carbon;

use App\Models\MongoDB\VisualizerModel;
use App\Models\PointCloud;
use App\Models\Project;

class GenerateModelData implements ShouldQueue
{
use dispatchable,InteractsWithQueue,Queueable,SerializesModels;

protected $pointcloud;

/**
 * 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 = 1200;

/**
 * The number of seconds to wait before retrying the job.
 *
 * @var int
 */
public $backoff = 120;

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

/**
 * Execute the job.
 *
 * @return void
 */
public function handle()
{
    // These commands can take +8 hours to execute in some cases
    ini_set('max_execution_time',0);
    set_time_limit(0);

    $pointcloud = $this->pointcloud;

    $modelID = $pointcloud->models[0]->model_id;

    $model = VisualizerModel::find($modelID);

    $IFCFileName = substr($model->filename,-5);

    $IFCFileLocation = "/var/www/app/storage/app/public/application/projects/{$model->project_uuid}/models/ifc/{$IFCFileName}.ifc";
    $PTSFileLocation = "/var/www/app/storage/app/public/{$pointcloud->storage_location}";
    $downSample = 15;
    $uuid = $model->project_uuid;
    $date = Carbon::parse($pointcloud->scan_date)->format('d/m/Y');
    $modelDataID = $model->model_data_id;

    $process = new Process(['BIMTool.sh',$IFCFileLocation,$PTSFileLocation,$downSample,$uuid,$modelID,$date,$modelDataID 
    ]);

    $process->setTimeout(1200);
    $process->setIdleTimeout(1200);
    $process->start();

    // Executes after the command finishes
    if (!$process->isSuccessful()) {

        throw new ProcessFailedException($process);

    } else {
        // Command was succesfull

        // Some code here

    }
}

/**
 * Catch error if job fails.
 *
 * @return \Symfony\Component\Process\Exception\ProcessFailedException
 */
public function Failed(ProcessFailedException $exception)
{
   return $exception;
}

我当然已经针对这个问题搜索了 Stackoverflow(以及与此相关的互联网),并尝试了我遇到的所有解决方案,但没有任何效果

到目前为止我尝试过的(但都没有奏效)

  • PHP.ini 中的 max_input_time 设置更改为 0、-1 和 1200
  • PHP.ini 中的 max_execution_time 设置更改为 0、-1 和 1200
  • $process->setTimeout(1200);
  • $process->setIdleTimeout(1200);
  • ini_set('max_execution_time',0);
  • set_time_limit(0);
  • 在主管命令中添加了 --timeout=0

环境配置

Linode 运行 Ubuntu 18.04.5 LTS
LAMP-stack
蟒蛇3
Laravel 5.8

主管配置

[program:laravel-worker]
process_name=%(program_name)s_%(process_num)02d
command=PHP /var/www/app/artisan queue:work database --sleep=5 --tries=3 --timeout=0 -- 
queue=default
autostart=true
autorestart=true
user=bc
numprocs=1
redirect_stderr=true
stdout_logfile=/var/www/app/worker.log

什么可能导致进程超过 60 秒超时错误?无论我尝试什么,我都会得到它。

编辑:(这为我解决了)

所以原来队列也有一个“缓存”。运行命令:

PHP artisan queue:restart

清除了作业缓存版本的队列。问题是我对代码所做的更改从未运行过,因此请务必运行此命令以确保作业队列使用的是最新代码

感谢输入!

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)