about summary refs log tree commit diff
path: root/lib/presque/JobQueueHandler.pm
blob: 7890b11e6c5948da9eea4f7977ac4152d06dcb6b (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
package presque::JobQueueHandler;

use Moose;
extends 'Tatsumaki::Handler';

with (
  'presque::Role::QueueName',
  'presque::Role::Error',
  'presque::Role::Response',
  'presque::Role::RequireQueue' => {methods => [qw/get/]},
);

__PACKAGE__->asynchronous(1);

sub get {
    my ( $self, $queue_name ) = @_;

    my $key = $self->_queue($queue_name);

    $self->application->redis->lrange(
        $key, 0, 9,
        sub {
            my $jobs = shift;
            $self->application->redis->llen(
                $key,
                sub {
                    my $size = shift;
                    my $lkey = $queue_name . '*';
                    $self->application->redis->keys(
                        $lkey,
                        sub {
                            my $total = shift;
                            my $stats = {
                                queue      => $queue_name,
                                jobs       => $jobs,
                                job_count  => $size,
                                queue_size => scalar @$total
                            };
                            $self->finish(JSON::encode_json $stats);
                        }
                    );
                }
            );
        }
    );
}

1;
__END__

=head1 NAME

presque::IndexHandler - a redis based message queue

=head1 DESCRIPTION

Return some informations about a queue.

=head1 AUTHOR

franck cuny E<lt>franck@lumberjaph.netE<gt>

=head1 SEE ALSO

=head1 LICENSE

Copyright 2010 by Linkfluence

L<http://linkfluence.net>

This library is free software; you can redistribute it and/or modify
it under the same terms as Perl itself.

=cut