使用laravel队列作业处理时,卡住了 [英] when using laravel queue job processing, getting stuck

查看:115
本文介绍了使用laravel队列作业处理时,卡住了的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在5.3.31上

因此它不能与

https://github.com/laravel/framework/issues/15179

获得300个职位后,我得到了

after 300ish jobs I get:

[2017-04-11 13:51:53] local.ERROR: Symfony\Component\Debug\Exception\FatalThrowableError: Call to a member function beginTransaction() on null in /var/www/html/www.myapp.com/vendor/laravel/framework/src/Illuminate/Database/Connection.php:612
Stack trace:
#0 /var/www/html/www.myapp.com/vendor/laravel/framework/src/Illuminate/Queue/DatabaseQueue.php(175): Illuminate\Database\Connection->beginTransaction()
#1 /var/www/html/www.myapp.com/vendor/laravel/framework/src/Illuminate/Queue/Worker.php(175): Illuminate\Queue\DatabaseQueue->pop('default')
#2 /var/www/html/www.myapp.com/vendor/laravel/framework/src/Illuminate/Queue/Worker.php(145): Illuminate\Queue\Worker->getNextJob(Object(Illuminate\Queue\DatabaseQueue), 'default')
#3 /var/www/html/www.myapp.com/vendor/laravel/framework/src/Illuminate/Queue/Worker.php(75): Illuminate\Queue\Worker->runNextJob('database', 'default', Object(Illuminate\Queue\WorkerOptions))
#4 /var/www/html/www.myapp.com/vendor/laravel/framework/src/Illuminate/Queue/Console/WorkCommand.php(100): Illuminate\Queue\Worker->daemon('database', 'default', Object(Illuminate\Queue\WorkerOptions))
#5 /var/www/html/www.myapp.com/vendor/laravel/framework/src/Illuminate/Queue/Console/WorkCommand.php(83): Illuminate\Queue\Console\WorkCommand->runWorker('database', 'default')
#6 [internal function]: Illuminate\Queue\Console\WorkCommand->fire()
#7 /var/www/html/www.myapp.com/vendor/laravel/framework/src/Illuminate/Container/Container.php(508): call_user_func_array(Array, Array)
#8 /var/www/html/www.myapp.com/vendor/laravel/framework/src/Illuminate/Console/Command.php(169): Illuminate\Container\Container->call(Array)
#9 /var/www/html/www.myapp.com/vendor/symfony/console/Command/Command.php(256): Illuminate\Console\Command->execute(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#10 /var/www/html/www.myapp.com/vendor/laravel/framework/src/Illuminate/Console/Command.php(155): Symfony\Component\Console\Command\Command->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#11 /var/www/html/www.myapp.com/vendor/symfony/console/Application.php(820): Illuminate\Console\Command->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#12 /var/www/html/www.myapp.com/vendor/symfony/console/Application.php(187): Symfony\Component\Console\Application->doRunCommand(Object(Illuminate\Queue\Console\WorkCommand), Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#13 /var/www/html/www.myapp.com/vendor/symfony/console/Application.php(118): Symfony\Component\Console\Application->doRun(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#14 /var/www/html/www.myapp.com/vendor/laravel/framework/src/Illuminate/Foundation/Console/Kernel.php(121): Symfony\Component\Console\Application->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#15 /var/www/html/www.myapp.com/artisan(35): Illuminate\Foundation\Console\Kernel->handle(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#16 {main}  

此错误不断重复出现

工作停滞了,什么也没有进展,什么也没有转移到失败队列中

the jobs are stuck, nothing advances, nothing gets moved to failed-queue neither

我发现的唯一解决方案是每隔几分钟通过cronjob停止主管工作,然后再次启动.远非最佳

the only solution is that I have found is stopping the supervisor workers via cronjob every couple minutes, and starting them again. Which is far from optimal

似乎以及整个服务器是否会不时地消失一次.也许是内存问题?我的实时服务器有1 GB的内存.

seems as well as if the whole server disappears once in a while quickly. Maybe a memory problem? i have 1 gb of memory for my live server.

推荐答案

这可能是两件事之一:

1.内存泄漏

如果您将队列作为守护进程运行,则随着时间的流逝,它们可能会耗尽内存.如果发生这种情况,您有三种选择.

If you are running your queues as a daemon process, then it is possible that over time they will run out of memory. If this occurs, you have three choices.

  • 找到停止内存泄漏的方式
  • 切换为使用queue:listen以确保PHP每次都重新启动
  • 运行包含$schedule->command('queue:restart')->hourly()的调度程序.这使您两全其美,因为您从守护进程中受益,只需每小时重新启动一次即可允许PHP重置.
  • Find a stop the memory leak
  • Switch to using queue:listen to ensure PHP restarts each time
  • Run a scheduler that includes $schedule->command('queue:restart')->hourly(). This gives you the best of both worlds, because you get the benefit of a daemon process, and just restart it once an hour to allow PHP to reset.

2.数据库连接失败

当前存在一个已知问题,即如果数据库连接在守护程序过程中断开,则它可能无法重新连接.公关正在进行中-请检查是否接受该公关,并应修复该错误: https: //github.com/laravel/framework/pull/19080

There is currently a known issue that if a DB connection goes away during a daemon process, it may not reconnect. A PR is in process here - so check if this gets accepted and the bug should be fixed: https://github.com/laravel/framework/pull/19080

这篇关于使用laravel队列作业处理时,卡住了的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆