about summary refs log tree commit diff
path: root/lib/presque/StatusHandler.pm
blob: 84a75dec7aca76cf1ccbcd28981717e6fe1d760c (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
package presque::StatusHandler;

use Moose;
extends 'Tatsumaki::Handler';
with qw/presque::Role::QueueName/;

__PACKAGE__->asynchronous(1);

use JSON;

before [qw/get/] => sub {
    my $self = shift;
    $self->response->header('application/json');
};

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

    my $conf = $self->application->config->{redis};
    my $stats = { redis => $conf->{host} . ':' . $conf->{port}, };

    if ($queue_name) {
        my $key = $self->_queue($queue_name);
        $self->application->redis->llen(
            $key,
            sub {
                my $size = shift;
                $stats->{queue} = $queue_name;
                $stats->{size}  = $size;
                my $json = JSON::encode_json($stats);
                $self->finish($json);
            }
        );
    }
    else {
        $self->application->redis->smembers(
            'QUEUESET',
            sub {
                my $res = shift;
                $stats->{queues} = $res;
                $stats->{size}   = scalar @$res;
                $self->finish( JSON::encode_json($stats) );
            }
        );
    }
}

1;
__END__

=head1 NAME

presque::IndexHandler - a redis based message queue

=head1 DESCRIPTION

=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