Redis Queue Failed Job is being logged to MySQL

2019-07-06 09:19发布

问题:

Queue driver is set to use Redis

QUEUE_DRIVER=redis

With

php /opt/artisan queue:work --tries=1 --queue="data-ingestion-default" --daemon

The error, we receive is

[2016-09-14 08:32:40] lumen.ERROR: InvalidArgumentException: Database 
[mysql] not 
configured. in /opt/vendor/illuminate/database/DatabaseManager.php:239
Stack trace:
#0 /opt/vendor/illuminate/database/DatabaseManager.php(158):     
Illuminate\Database\DatabaseManager->getConfig('mysql')
#1 /opt/vendor/illuminate/database/DatabaseManager.php(68):   
Illuminate\Database\DatabaseManager->makeConnection('mysql')
#2 /opt/vendor/illuminate/queue/Failed/DatabaseFailedJobProvider.php(110): 
Illuminate\Database\DatabaseManager->connection('mysql')
#3 /opt/vendor/illuminate/queue/Failed/DatabaseFailedJobProvider.php(58):    
Illuminate\Queue\Failed\DatabaseFailedJobProvider->getTable()
#4 /opt/vendor/illuminate/queue/Worker.php(313): 
Illuminate\Queue\Failed\DatabaseFailedJobProvider->log('redis', 'data-ingestion-...',    
'{"job":"Illumin...')
#5 /opt/vendor/illuminate/queue/Worker.php(204): Illuminate\Queue\Worker-
>logFailedJob('redis', Object(Illuminate\Queue\Jobs\RedisJob))
#6 /opt/vendor/illuminate/queue/Worker.php(156): Illuminate\Queue\Worker->process('redis',   
Object(Illuminate\Queue\Jobs\RedisJob), '1', 0)
#7 /opt/vendor/illuminate/queue/Worker.php(111): Illuminate\Queue\Worker->pop(NULL, 'data-   
ingestion-...', 0, 3, '1')
#8 /opt/vendor/illuminate/queue/Worker.php(85): Illuminate\Queue\Worker-
>runNextJobForDaemon(NULL, 'data-ingestion-...', 0, 3, '1')
#9 /opt/vendor/illuminate/queue/Console/WorkCommand.php(119): Illuminate\Queue\Worker-
>daemon(NULL, 'data-ingestion-...', 0, 128, 3, '1')
#10 /opt/vendor/illuminate/queue/Console/WorkCommand.php(78): 
Illuminate\Queue\Console\WorkCommand->runWorker(NULL, 'data-ingestion-...', 0, 128, true)

It appears that the error is due to the Worker attempting to log the failed job to a mysql database.

However, we are not using MySQL in this instance, and if we were in config/database.php there is no 'mysql' in connection, and the default db is called 'development'.

回答1:

In config/queue.php take a look at failed config the default is:

'failed' => [
        'database' => env('DB_CONNECTION', 'mysql'),
        'table'    => 'failed_jobs',
    ],

change it to use redis

you can see the whole config file in the github reop laravel/config/queue.php



回答2:

you can not do it with redis driver. However, if you use Laravel Horizon, Horizon will automatically save your failed jobs in Redis