diff options
Diffstat (limited to 'lib/presque/StatusHandler.pm')
-rw-r--r-- | lib/presque/StatusHandler.pm | 72 |
1 files changed, 72 insertions, 0 deletions
diff --git a/lib/presque/StatusHandler.pm b/lib/presque/StatusHandler.pm new file mode 100644 index 0000000..18be7cd --- /dev/null +++ b/lib/presque/StatusHandler.pm @@ -0,0 +1,72 @@ +package presque::StatusHandler; + +use Moose; +extends 'Tatsumaki::Handler'; +__PACKAGE__->asynchronous(1); + +use JSON; + +before [qw/get/] => sub { + my $self = shift; + $self->response->header('application/json'); +}; + +sub get { + my ( $self, $queue_name ) = @_; + + $self->response->header( 'Content-Type' => 'application/json' ); + + my $conf = $self->application->config->{redis}; + my $stats = { redis => $conf->{host} . ':' . $conf->{port}, }; + + if ($queue_name) { + my $key = $queue_name . ":queue"; + $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 |