laravel 如何删除所有排队的作业,因为它会导致错误?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/47212165/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to remove all queued jobs because it's causing errors?
提问by Joshua Leung
My website queues email sending jobs to the jobs
table. I think the email server has some problem and it can't send emails so the jobs are stuck at the jobs table. Now maybe there are too many jobs, and I receive this error message:
我的网站将电子邮件发送到jobs
桌子上排队。我认为电子邮件服务器有一些问题,它无法发送电子邮件,因此作业卡在作业表中。现在可能有太多作业,我收到此错误消息:
Next exception 'Illuminate\Database\QueryException' with message 'SQLSTATE[22003]: Numeric value out of range: 1264 Out of range value for column 'attempts' at row 1 (SQL: update `jobs` set `reserved_at` = 1510263884, `attempts` = 256 where `id` = 342)' in /var/www/vhosts/parcgilley.com/httpdocs/vendor/laravel/framework/src/Illuminate/Database/Connection.php:647
#0 /var/www/vhosts/parcgilley.com/httpdocs/vendor/laravel/framework/src/Illuminate/Database/Connection.php(607): Illuminate\Database\Connection->runQueryCallback('update `jobs` s...', Array, Object(Closure))
#1 /var/www/vhosts/parcgilley.com/httpdocs/vendor/laravel/framework/src/Illuminate/Database/Connection.php(477): Illuminate\Database\Connection->run('update `jobs` s...', Array, Object(Closure))
#2 /var/www/vhosts/parcgilley.com/httpdocs/vendor/laravel/framework/src/Illuminate/Database/Connection.php(416): Illuminate\Database\Connection->affectingStatement('update `jobs` s...', Array)
So I am wondering how do I flush all the queued jobs to clear the table? I can't access the database to remove the data in the table, so is there any command line to do so? I don't have a failed queue table.
所以我想知道如何刷新所有排队的作业以清除表格?我无法访问数据库以删除表中的数据,那么是否有任何命令行可以这样做?我没有失败的队列表。
回答by Marcin Nabia?ek
Assuming you are using database driver you can use:
假设您正在使用数据库驱动程序,您可以使用:
DB::table('jobs')->delete();
to delete all the jobs.
删除所有作业。
The other thing is that you should always run queue worker with attempts set:
另一件事是您应该始终运行带有尝试设置的队列工作器:
php artisan queue:work --tries=3
Also remember that whenever you change your application code, you should restart your workers:
还要记住,无论何时更改应用程序代码,都应该重新启动工作程序:
php artisan queue:restart
( I assume you use supervisor that will start workers again).
(我假设您使用将再次启动工人的主管)。