How to remove all queued jobs because it's causing errors?

风流意气都作罢 提交于 2019-12-11 01:29:41

问题


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:

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.


回答1:


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).



来源:https://stackoverflow.com/questions/47212165/how-to-remove-all-queued-jobs-because-its-causing-errors

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!