about summary refs log tree commit diff
path: root/lib/presque/JobQueueHandler.pm
blob: b77251ed836e1ca3671eafa02d3394b8308399c9 (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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
package presque::JobQueueHandler;

use Moose;
extends 'Tatsumaki::Handler';

with
  'presque::Role::Queue::Names',
  'presque::Role::Error',
  'presque::Role::Response',
  'presque::Role::Queue::WithQueueName' => {methods => [qw/get/]};

__PACKAGE__->asynchronous(1);

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

    $self->application->redis->llen(
        $self->_queue($queue_name),
        sub {
            my $size = shift;
            $self->application->redis->hget(
                $self->_queue_processed,
                $queue_name,
                sub {
                    my $processed = shift;
                    $self->application->redis->hget(
                        $self->_queue_failed,
                        $queue_name,
                        sub {
                            my $failed = shift;
                            $self->entity(
                                {   queue_name    => $queue_name,
                                    job_count     => $size || 0,
                                    job_failed    => $failed || 0,
                                    job_processed => $processed || 0,
                                }
                            );
                        }
                    );
                }
            );
        }
    );
}

1;
__END__

=head1 NAME

presque::JobQueueHandler

=head1 SYNOPSIS

    # grab info from a queue
    curl http://localhost:5000/j/queuename

=head1 DESCRIPTION

Return some informations about a queue.

=head1 METHODS

=head2 GET

=over 4

=item path

/j/:queue_name

=item request

=item response

content-type: application/json

code: 200

content : {"queue_name":"foo","job_count":"0","job_processed":"127","job_failed":"37"}

=back

This method return some statistics about a queue. The informations are :

=over 2

=item B<queue_name>

name of the queue

=item B<job_count>

how many jobs are in the queue

=item B<job_processed>

how many jobs have been processed so far for this queue

=item B<job_failed>

how many job have been reported as failed for this 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