laravel 使用redis队列的问题

kangfq
  • 39

使用laravel队列的过程中使用redis驱动进行队列测试

//队列文件名为 Createfile.php

public function handle()
    {
        Log::alert('redis 队列测试'.$this->b);
    }

控制器中方法如下:

public function queue()
    {
        Createfile::dispatch(9);
    }

问题如下

在我打开php artisan queue:listen进行监听的情况下,我的队列是成功执行的,我可以在我的日志文件看到[2019-07-15 08:46:16] local.ALERT: redis 队列测试9

但是当我关闭监听的时候,我将任务推送到队列,然后我再开启监听,队列执行失败,提示超时,查看日志记录如下

[2019-07-15 08:54:47] local.ERROR: App\Jobs\Createfile has been attempted too many times or run too long. The job may have previously timed out. {"exception":"[object] (Illuminate\\Queue\\MaxAttemptsExceededException(code: 0): App\\Jobs\\Createfile has been attempted too many times or run too long. The job may have previously timed out. at E:\\laragon\\www\\orange\\vendor\\laravel\\framework\\src\\Illuminate\\Queue\\Worker.php:405)
[stacktrace]
#0 E:\\laragon\\www\\orange\\vendor\\laravel\\framework\\src\\Illuminate\\Queue\\Worker.php(321): Illuminate\\Queue\\Worker->markJobAsFailedIfAlreadyExceedsMaxAttempts('redis', Object(Illuminate\\Queue\\Jobs\\RedisJob), 0)
#1 E:\\laragon\\www\\orange\\vendor\\laravel\\framework\\src\\Illuminate\\Queue\\Worker.php(277): Illuminate\\Queue\\Worker->process('redis', Object(Illuminate\\Queue\\Jobs\\RedisJob), Object(Illuminate\\Queue\\WorkerOptions))
#2 E:\\laragon\\www\\orange\\vendor\\laravel\\framework\\src\\Illuminate\\Queue\\Worker.php(230): Illuminate\\Queue\\Worker->runJob(Object(Illuminate\\Queue\\Jobs\\RedisJob), 'redis', Object(Illuminate\\Queue\\WorkerOptions))
#3 E:\\laragon\\www\\orange\\vendor\\laravel\\framework\\src\\Illuminate\\Queue\\Console\\WorkCommand.php(102): Illuminate\\Queue\\Worker->runNextJob('redis', 'default', Object(Illuminate\\Queue\\WorkerOptions))
#4 E:\\laragon\\www\\orange\\vendor\\laravel\\framework\\src\\Illuminate\\Queue\\Console\\WorkCommand.php(86): Illuminate\\Queue\\Console\\WorkCommand->runWorker('redis', 'default')
#5 [internal function]: Illuminate\\Queue\\Console\\WorkCommand->handle()
#6 E:\\laragon\\www\\orange\\vendor\\laravel\\framework\\src\\Illuminate\\Container\\BoundMethod.php(32): call_user_func_array(Array, Array)
#7 E:\\laragon\\www\\orange\\vendor\\laravel\\framework\\src\\Illuminate\\Container\\BoundMethod.php(90): Illuminate\\Container\\BoundMethod::Illuminate\\Container\\{closure}()
#8 E:\\laragon\\www\\orange\\vendor\\laravel\\framework\\src\\Illuminate\\Container\\BoundMethod.php(34): Illuminate\\Container\\BoundMethod::callBoundMethod(Object(Illuminate\\Foundation\\Application), Array, Object(Closure))
#9 E:\\laragon\\www\\orange\\vendor\\laravel\\framework\\src\\Illuminate\\Container\\Container.php(576): Illuminate\\Container\\BoundMethod::call(Object(Illuminate\\Foundation\\Application), Array, Array, NULL)
#10 E:\\laragon\\www\\orange\\vendor\\laravel\\framework\\src\\Illuminate\\Console\\Command.php(183): Illuminate\\Container\\Container->call(Array)
#11 E:\\laragon\\www\\orange\\vendor\\symfony\\console\\Command\\Command.php(255): Illuminate\\Console\\Command->execute(Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Illuminate\\Console\\OutputStyle))
#12 E:\\laragon\\www\\orange\\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))
#13 E:\\laragon\\www\\orange\\vendor\\symfony\\console\\Application.php(921): Illuminate\\Console\\Command->run(Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Symfony\\Component\\Console\\Output\\ConsoleOutput))
#14 E:\\laragon\\www\\orange\\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))
#15 E:\\laragon\\www\\orange\\vendor\\symfony\\console\\Application.php(149): Symfony\\Component\\Console\\Application->doRun(Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Symfony\\Component\\Console\\Output\\ConsoleOutput))
#16 E:\\laragon\\www\\orange\\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))
#17 E:\\laragon\\www\\orange\\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))
#18 E:\\laragon\\www\\orange\\artisan(37): Illuminate\\Foundation\\Console\\Kernel->handle(Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Symfony\\Component\\Console\\Output\\ConsoleOutput))
#19 {main}
"} 

再次重新执行队列也无法执行此队列,不知道是什么原因.
另外还有一个问题,就是虽然使用了redis做为队列驱动,但是队列失败的信息依然是保存在SQL数据库的failed_jobs里面,而不是redis里面,这样子是正常的吗?谢谢各位了.

回复
阅读 3.9k
1 个回答

失败的队列在 failed_jobs 表 应该是代码里配置的

/*
    |--------------------------------------------------------------------------
    | Failed Queue Jobs
    |--------------------------------------------------------------------------
    |
    | These options configure the behavior of failed queue job logging so you
    | can control which database and table are used to store the jobs that
    | have failed. You may change them to any database / table you wish.
    |
    */

    'failed' => [
        'database' => env('DB_CONNECTION', 'mysql'),
        'table' => 'crm_failed_jobs',
    ],
    
你知道吗?

宣传栏