Reputation: 3475
I've been using the Queue system in Laravel 4 and it works great! - I was wondering if there was a way to view what is actually in the Queue? I'm using redis for the back-end.
Upvotes: 9
Views: 2732
Reputation: 4579
not exactly answer for your case but just as reference for others.
If you are using beanstalkd driver than you can access that information like this:
$stats = Queue::getPheanstalk()->stats();
where the stats variable will have these properties:
array(
'current-jobs-urgent' => '0',
'current-jobs-ready' => '5',
'current-jobs-reserved' => '0',
'current-jobs-delayed' => '0',
'current-jobs-buried' => '0',
'cmd-put' => '95',
'cmd-peek' => '0',
'cmd-peek-ready' => '130',
'cmd-peek-delayed' => '32',
'cmd-peek-buried' => '32',
'cmd-reserve' => '0',
'cmd-reserve-with-timeout' => '1142',
'cmd-delete' => '90',
'cmd-release' => '1124',
'cmd-use' => '194',
'cmd-watch' => '0',
'cmd-ignore' => '0',
'cmd-bury' => '0',
'cmd-kick' => '0',
'cmd-touch' => '0',
'cmd-stats' => '37',
'cmd-stats-job' => '32',
'cmd-stats-tube' => '78822',
'cmd-list-tubes' => '78822',
'cmd-list-tube-used' => '0',
'cmd-list-tubes-watched' => '0',
'cmd-pause-tube' => '0',
'job-timeouts' => '3',
'total-jobs' => '95',
'max-job-size' => '65535',
'current-tubes' => '1',
'current-connections' => '1',
'current-producers' => '0',
'current-workers' => '0',
'current-waiting' => '0',
'total-connections' => '40679',
'pid' => '15937',
'version' => '1.10',
'rusage-utime' => '6.184000',
'rusage-stime' => '16.808000',
'uptime' => '146790',
'binlog-oldest-index' => '0',
'binlog-current-index' => '0',
'binlog-records-migrated' => '0',
'binlog-records-written' => '0',
'binlog-max-size' => '10485760',
'id' => '56d8d2c9888219bc',
'hostname' => 'ddeath-pc',
)
so then for example $stats['current-jobs-ready']
will return jobs ready to be processed by worker.
Upvotes: 0
Reputation: 60048
I spent some time on this digging around the Queue driver and the API. I was able to find an answer for you.
Short TL;DR version:
There is no native Queue::getList()
(or similar) function on the Queue interface.
But this will get you a list of all queued jobs in your default
Redis queue waiting to be processed:
$list = (Queue::getRedis()->command('LRANGE',['queues:default', '0', '-1']));
change default
to another name if you run multiple queue tubes.
Be warned that command might result in a very large dataset being returned (its like dumping part of your database) - so you might just want to get the number of jobs queued instead:
$queue_length = (Queue::getRedis()->command('LLEN',['queues:default']));
Longer version:
There is no native Queue::getList()
(or similar) function on the Queue interface. But I noticed that it is possible to get the Redis driver from the Queue interface:
$redis = Queue::getRedis();
Digging into the Redis driver - we can see there is a function called command()
. Which is defined as
command(string $method, array $parameters = array())
Run a command against the Redis database.
So that means we can now run any native Redis command through Laravel onto the Redis instance.
A full list of Redis commands is here
By browsing that list - we have a number of helpful commands which we can use for Queues.
Firstly - you can view all KEYS
available - which might be useful if you are not sure of the name of your queues:
$keys = Queue::getRedis()->command('KEYS',['*']);
You can also make sure a specific KEY exists before running another operation - like this:
if (Queue::getRedis()->command('EXISTS',['queues:default']))
{
// Queues:default key exists!
}
Also - you can get the length of the queue - which is useful
$queue_length = (Queue::getRedis()->command('LLEN',['queues:default']));
And finally you can get the entire list of queues with this
$list = (Queue::getRedis()->command('LRANGE',['queues:default1', '0', '-1']));
If you dont want the full list (perhaps your queue is quite large) - you can get a subset of it. Read more a LRANGE at the Redis docs here.
Upvotes: 25