【问题标题】:Laravel Queue Not working as expected. Row inserted in table but not attemptedLaravel 队列未按预期工作。行已插入表中但未尝试
【发布时间】:2018-10-18 00:56:23
【问题描述】:

到目前为止我做了什么:

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');
}

我想在点击 url 后立即发送邮件。 当我以 3 秒的延迟运行 php artisan queue:listen 时,需要很长时间才能采取任何行动。我可以在 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 访问权限的服务器上运行它?

【问题讨论】:

    标签: laravel laravel-queue


    【解决方案1】:
    The process exceeded the timeout of 60 seconds
    

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

    来自Laravel docs

    1.使用 --timeout

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

    2。使用 $timeout

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

    关于您的其他问题:

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

    没有

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

    使用SupervisorLaravel Horizon(如果您使用Redis 作为队列)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-11-30
      • 2019-10-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-03-26
      • 2020-04-26
      相关资源
      最近更新 更多