about summary refs log tree commit diff
path: root/lib/presque/StatusHandler.pm
blob: 8fee47ecd8962c7a2ce5ff5f8a82c3c4d88506fb (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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
package presque::StatusHandler;

use JSON;
use Moose;
extends 'Tatsumaki::Handler';
with
  'presque::Role::Queue::Names',
  'presque::Role::Error',
  'presque::Role::Response';

__PACKAGE__->asynchronous(1);

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

    if ($queue_name) {
        my $key = $self->_queue($queue_name);
        $self->application->redis->llen(
            $key,
            sub {
                my $size = shift;
                $self->entity({queue => $queue_name, size => $size});
            }
        );
    }
    else {
        $self->application->redis->smembers(
            $self->_queue_set,
            sub {
                my $res = shift;
                $self->entity({queues => $res, size => scalar @$res});
            }
        );
    }
}

1;
__END__

=head1 NAME

presque::StatusHandler - return the current size of a queue

=head1 DESCRIPTION

Return the current size of a queue

=head2 GET

=over 4

=item path

/status/:queue_name

=item request

=item response

content-type : application/json

code : 200

content : {"queue":"queue_name", "size":10}

=back

The response contains the following informations

=over 2

=item B<queue>

name of the queue

=item B<size>

size of the queue

=back

=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