How to get all pending jobs in laravel queue on re

2019-03-11 02:02发布

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.

标签: laravel redis
6条回答
Emotional °昔
2楼-- · 2019-03-11 02:10

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');
查看更多
Juvenile、少年°
3楼-- · 2019-03-11 02:13

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

查看更多
SAY GOODBYE
4楼-- · 2019-03-11 02:15

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.

查看更多
贼婆χ
5楼-- · 2019-03-11 02:16

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

查看更多
劳资没心,怎么记你
6楼-- · 2019-03-11 02:18

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!

查看更多
Luminary・发光体
7楼-- · 2019-03-11 02:26

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

查看更多
登录 后发表回答