How to get all pending jobs in laravel queue on re

2019-03-11 02:15发布

问题:

Queue listener was not started on a server, some jobs where pushed (using Redis driver).

How could I count (or get all) theses jobs ? I did not found any artisan command to get this information.

回答1:

If someone still looking for an answer here is the way I do it:

$connection = null;
$default = 'default';

//For the delayed jobs
var_dump( \Queue::getRedis()->connection($connection)->zrange('queues:'.$default.':delayed' ,0, -1) );

//For the reserved jobs
var_dump( \Queue::getRedis()->connection($connection)->zrange('queues:'.$default.':reserved' ,0, -1) );

$connection is the Redis connection name which is null by default, and The $queue is the name of the queue / tube which is 'default' by default!



回答2:

Since Laravel 5.3 you can simply use Queue::size() (see PR).



回答3:

You can also use the Redis Facade directly by doing this:

use Redis;

\Redis::lrange('queues:$queueName', 0, -1);

Tested in Laravel 5.6 but should work for all 5.X.



回答4:

You can install Horizon. Laravel Horizon provides a dashboard for monitoring your queues, and allows you to do more configuration to your queue.

composer require laravel/horizon

php artisan vendor:publish --provider="Laravel\Horizon\HorizonServiceProvider"

You have to set .env config file and config/horizon.php file.

Tested with Laravel 5.6



回答5:

If anybody is still looking approach for the older versions of the Laravel:

$connection = 'queue';
$queueName = 'default';
$totalQueuedLeads = Redis::connection($connection)->zcount('queues:'.$queueName.':delayed' , '-inf', '+inf');


回答6:

I am an PHP Laravel dev, 3 years, I have just known these command recently, so shame on me. ;(

If you are using redis driver for your queue, you can count all remaining jobs by name:

use Redis;
$queueName = 'default';
echo Redis::llen('queues:' . $queueName);

// To count by status:
echo Redis::zcount('queues:' . $queueName . ':delayed', '-inf', '+inf');
echo Redis::zcount('queues:' . $queueName . ':reserved', '-inf', '+inf');

To see the result immediately, you can use php artisan tinker and hit Redis::llen('queues:default');.



标签: laravel redis