laravel - 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 访问权限的服务器中运行它?
解决方案
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 访问权限的服务器中运行它?
使用Supervisor或Laravel Horizon(如果你使用 Redis 作为队列)
推荐阅读
- javascript - 如何将事件监听器添加到 HTML 文件上的简单谷歌地图
- python - 如何将 [2,3,4] 转换为 [0,0,1,1,1,2,2,2,2] 以利用 tf.math.segment_sum?
- python - 即使字符串中存在子字符串,python re.search 也会返回 None
- css - 是否可以找到导致规则在 Chrome 检查器中显示为灰色的父 CSS?
- node.js - 无法识别的表达式 '$nin' Mongodb
- julia - 尝试在 Windows 上的 Julia 中安装 Pardiso
- c# - C#检测光标是否隐藏
- amazon-web-services - Ansbile + AWS 私有主机配置
- javascript - 为什么“从'datatables.net'导入数据表”可以在某些机器上工作,而在其他机器上不行?
- python - 无法使用 plt.plot() 从散点图中删除连接线