laravel5.8 REDIS队列问题

队列运行久了就会抛出MODEL找不到的异常,重启队列后就可以使用了

Log::debug('$waybillToSetHawb-failed');
Log::debug($this->waybillToSetHawb);
Log::debug($exception);

报错信息:

[2021-03-04 18:44:06] production.DEBUG: Illuminate\Database\Eloquent\ModelNotFoundException: No query results for model [App\Model\WaybillToSetHawb]. in /mnt/data/wwwroot/baidu.com/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Builder.php:454
Stack trace:
#0 /mnt/data/wwwroot/baidu.com/vendor/laravel/framework/src/Illuminate/Queue/SerializesAndRestoresModelIdentifiers.php(102): Illuminate\Database\Eloquent\Builder->firstOrFail()
#1 /mnt/data/wwwroot/baidu.com/vendor/laravel/framework/src/Illuminate/Queue/SerializesAndRestoresModelIdentifiers.php(57): App\Jobs\EditItemAndSetPrint2->restoreModel(Object(Illuminate\Contracts\Database\ModelIdentifier))
#2 /mnt/data/wwwroot/baidu.com/vendor/laravel/framework/src/Illuminate/Queue/SerializesModels.php(45): App\Jobs\EditItemAndSetPrint2->getRestoredPropertyValue(Object(Illuminate\Contracts\Database\ModelIdentifier))
#3 [internal function]: App\Jobs\EditItemAndSetPrint2->__wakeup()
#4 /mnt/data/wwwroot/baidu.com/vendor/laravel/framework/src/Illuminate/Queue/CallQueuedHandler.php(42): unserialize('O:29:"App\\Jobs\\...')
#5 /mnt/data/wwwroot/baidu.com/vendor/laravel/framework/src/Illuminate/Queue/Jobs/Job.php(88): Illuminate\Queue\CallQueuedHandler->call(Object(Illuminate\Queue\Jobs\RedisJob), Array)
#6 /mnt/data/wwwroot/baidu.com/vendor/laravel/framework/src/Illuminate/Queue/Worker.php(337): Illuminate\Queue\Jobs\Job->fire()
#7 /mnt/data/wwwroot/baidu.com/vendor/laravel/framework/src/Illuminate/Queue/Worker.php(283): Illuminate\Queue\Worker->process('redis', Object(Illuminate\Queue\Jobs\RedisJob), Object(Illuminate\Queue\WorkerOptions))
#8 /mnt/data/wwwroot/baidu.com/vendor/laravel/framework/src/Illuminate/Queue/Worker.php(118): Illuminate\Queue\Worker->runJob(Object(Illuminate\Queue\Jobs\RedisJob), 'redis', Object(Illuminate\Queue\WorkerOptions))
#9 /mnt/data/wwwroot/baidu.com/vendor/laravel/framework/src/Illuminate/Queue/Console/WorkCommand.php(102): Illuminate\Queue\Worker->daemon('redis', 'EditItemAndSetP...', Object(Illuminate\Queue\WorkerOptions))
#10 /mnt/data/wwwroot/baidu.com/vendor/laravel/framework/src/Illuminate/Queue/Console/WorkCommand.php(86): Illuminate\Queue\Console\WorkCommand->runWorker('redis', 'EditItemAndSetP...')
#11 [internal function]: Illuminate\Queue\Console\WorkCommand->handle()
#12 /mnt/data/wwwroot/baidu.com/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(32): call_user_func_array(Array, Array)
#13 /mnt/data/wwwroot/baidu.com/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(90): Illuminate\Container\BoundMethod::Illuminate\Container\{closure}()
#14 /mnt/data/wwwroot/baidu.com/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(34): Illuminate\Container\BoundMethod::callBoundMethod(Object(Illuminate\Foundation\Application), Array, Object(Closure))
#15 /mnt/data/wwwroot/baidu.com/vendor/laravel/framework/src/Illuminate/Container/Container.php(576): Illuminate\Container\BoundMethod::call(Object(Illuminate\Foundation\Application), Array, Array, NULL)
#16 /mnt/data/wwwroot/baidu.com/vendor/laravel/framework/src/Illuminate/Console/Command.php(183): Illuminate\Container\Container->call(Array)
#17 /mnt/data/wwwroot/baidu.com/vendor/symfony/console/Command/Command.php(255): Illuminate\Console\Command->execute(Object(Symfony\Component\Console\Input\ArgvInput), Object(Illuminate\Console\OutputStyle))
#18 /mnt/data/wwwroot/baidu.com/vendor/laravel/framework/src/Illuminate/Console/Command.php(170): Symfony\Component\Console\Command\Command->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Illuminate\Console\OutputStyle))
#19 /mnt/data/wwwroot/baidu.com/vendor/symfony/console/Application.php(1009): Illuminate\Console\Command->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#20 /mnt/data/wwwroot/baidu.com/vendor/symfony/console/Application.php(273): Symfony\Component\Console\Application->doRunCommand(Object(Illuminate\Queue\Console\WorkCommand), Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#21 /mnt/data/wwwroot/baidu.com/vendor/symfony/console/Application.php(149): Symfony\Component\Console\Application->doRun(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#22 /mnt/data/wwwroot/baidu.com/vendor/laravel/framework/src/Illuminate/Console/Application.php(90): Symfony\Component\Console\Application->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#23 /mnt/data/wwwroot/baidu.com/vendor/laravel/framework/src/Illuminate/Foundation/Console/Kernel.php(133): Illuminate\Console\Application->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#24 /mnt/data/wwwroot/baidu.com/artisan(37): Illuminate\Foundation\Console\Kernel->handle(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#25 {main} 

有没有大佬遇到过

《L04 微信小程序从零到发布》
从小程序个人账户申请开始,带你一步步进行开发一个微信小程序,直到提交微信控制台上线发布。
《L03 构架 API 服务器》
你将学到如 RESTFul 设计风格、PostMan 的使用、OAuth 流程,JWT 概念及使用 和 API 开发相关的进阶知识。
讨论数量: 5

有没有大佬遇到过···

3年前 评论

这个错误遇到过,是 Model->find() 找不到数据

3年前 评论
pleaseyang (楼主) 3年前

我记得 文档说 消费进程里面 尽量用 DB,不要用 model

3年前 评论
  • 数据被删除了。
  • 推了队列,但是推的数据实际上没有提交,回滚了,导致队列运行的时候查不到。
  • 有主从库,但是推队列的时候,从库还没有同步过来。
3年前 评论

在向任务中注入 Eloquent 模型时,模型被放入队列前将被自动序列化并在执行任务时还原。但是,如果在任务等待执行时删除了模型,任务可能会失败并抛出 ModelNotFoundException

为了方便,你可以选择设置任务的 deleteWhenMissingModels 属性为 true 来自动地删除缺失模型的任务。

/**
 * 如果模型缺失即删除任务。
 *
 * @var bool
 */
public $deleteWhenMissingModels = true;

文档地址

3年前 评论
pleaseyang (楼主) 3年前
荒街! (作者) 3年前

讨论应以学习和精进为目的。请勿发布不友善或者负能量的内容,与人为善,比聪明更重要!