blob: 65867e3fe2ea5e689db1b2c603dce798c4c7ff09 (
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
|
package presque::JobQueueHandler;
use Moose;
extends 'Tatsumaki::Handler';
__PACKAGE__->asynchronous(1);
before [qw/get/] => sub {
my $self = shift;
$self->response->header('Content-Type' => 'application/json');
};
sub get {
my ( $self, $queue_name ) = @_;
if (!$queue_name) {
$self->response->code(404);
$self->finish({error => 'queue name is missing'});
return;
}
my $key = $queue_name . ':queue';
$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
|