summaryrefslogtreecommitdiff
path: root/lib/presque/StatusHandler.pm
diff options
context:
space:
mode:
authorfranck cuny <franck@lumberjaph.net>2010-04-14 10:38:18 +0200
committerfranck cuny <franck@lumberjaph.net>2010-04-14 10:38:18 +0200
commit4f826bb26a779a73a9e97861809abc88f9761e59 (patch)
treeb9dac2f91cb64e865dc146db35a801004959626e /lib/presque/StatusHandler.pm
parentadd templates (diff)
downloadpresque-4f826bb26a779a73a9e97861809abc88f9761e59.tar.gz
update handlers, add POD, ...
Diffstat (limited to '')
-rw-r--r--lib/presque/StatusHandler.pm72
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