首页 > 解决方案 > Laravel 队列未按预期工作。行已插入表中但未尝试

问题描述

到目前为止我做了什么:

1) 将队列驱动程序更新到 .env 中的数据库

2)我的邮件控制器功能如下:

public function sendEmail()
{
   $emailJob = (new SendEmailJob())->delay(Carbon::now()->addSeconds(3));
   dispatch($emailJob);
    exit();
}

3) SendEmailJob 句柄

public function handle()
{
    Mail::to('mail@gmail.com')->send(new SendMailable());
    echo 'email sent';
}

4) SendMailable Mail 有以下内容

public function build()
{
    return $this->view('emails.ownership');
}

我想在点击网址后几乎立即发送邮件。由于我php artisan queue:listen以 3 秒的延迟运行,因此需要很长时间才能采取任何行动。我可以在 0 次尝试的作业表上看到一些数据。

很长一段时间后,在命令窗口中弹出以下错误

   Symfony\Component\Process\Exception\ProcessTimedOutException  : The process ""C:\wamp64\bin\php\php7.2.10\php.exe" "artisan" queue:work  --once --queue="default" --delay=0 --memory=128 --sleep=3 --tries=0" e
xceeded the timeout of 60 seconds.

  at C:\wamp64\www\project\vendor\symfony\process\Process.php:1154
    1150|
    1151|         if (null !== $this->timeout && $this->timeout < microtime(true) - $this->starttime) {
    1152|             $this->stop(0);
    1153|
  > 1154|             throw new ProcessTimedOutException($this, ProcessTimedOutException::TYPE_GENERAL);
    1155|         }
    1156|
    1157|         if (null !== $this->idleTimeout && $this->idleTimeout < microtime(true) - $this->lastOutputTime) {
    1158|             $this->stop(0);

  Exception trace:

  1   Symfony\Component\Process\Process::checkTimeout()
      C:\wamp64\www\project\vendor\symfony\process\Process.php:383

  2   Symfony\Component\Process\Process::wait()
      C:\wamp64\www\project\vendor\symfony\process\Process.php:202

通过,可以直接发送邮件的方式没有这个队列的东西。另外,这是强制运行 php artisan queue:listen 的吗?我应该如何在没有 shell 访问权限的服务器中运行它?

标签: laravellaravel-queue

解决方案


The process exceeded the timeout of 60 seconds

毫不奇怪,要解决此问题,您必须增加作业的超时时间。为此,您可以使用命令中的--timeout选项queue:work来增加超时以表示180秒数,或者在作业类中定义变量,如下所示:public $timeout = 180;

Laravel 文档中,

1.使用--timeout

可以使用 Artisan 命令行上的 --timeout 开关指定作业可以运行的最大秒数

2. 使用 $timeout

您还可以定义作业应允许在作业类本身上运行的最大秒数。如果在作业上指定了超时,它将优先于在命令行中指定的任何超时

对于您的其他问题:

这是强制运行 php artisan queue:listen 吗?

我应该如何在没有 shell 访问权限的服务器中运行它?

使用SupervisorLaravel Horizo​​n(如果你使用 Redis 作为队列)


推荐阅读