File Coverage

blib/lib/Kevin/Command/kevin/workers.pm
Criterion Covered Total %
statement 15 32 46.8
branch n/a
condition n/a
subroutine 5 11 45.4
pod 1 1 100.0
total 21 44 47.7


line stmt bran cond sub pod time code
1              
2             package Kevin::Command::kevin::workers;
3             $Kevin::Command::kevin::workers::VERSION = '0.5.2'; # TRIAL
4             # ABSTRACT: Command to list Minion workers
5 1     1   15374 use Mojo::Base 'Mojolicious::Command';
  1         2  
  1         5  
6              
7 1     1   136 use Kevin::Commands::Util ();
  1         2  
  1         16  
8 1     1   5 use Mojo::Util qw(getopt);
  1         1  
  1         43  
9 1     1   5 use Text::Yeti::Table qw(render_table);
  1         1  
  1         34  
10 1     1   4 use Time::HiRes qw(time);
  1         2  
  1         5  
11              
12             has description => 'List Minion workers';
13             has usage => sub { shift->extract_usage };
14              
15             sub run {
16 0     0 1   my ($self, @args) = @_;
17              
18 0           my $app = $self->app;
19 0           my $minion = $app->minion;
20              
21 0           my ($args, $options) = ([], {});
22 0           getopt \@args,
23             'l|limit=i' => \(my $limit = 100),
24             'o|offset=i' => \(my $offset = 0);
25              
26 0           my $results = $minion->backend->list_workers($offset, $limit, $options);
27 0           my $items = $results->{workers};
28              
29 0           my $spec = $self->_table_spec;
30 0           render_table($items, $spec);
31             }
32              
33             *_running_since = *Kevin::Commands::Util::_running_since;
34              
35             sub _table_spec {
36 0     0     my $now = time;
37             return [
38             qw(id ),
39 0     0     ['host', sub {"$_[0]:$_[1]{pid}"}, 'HOST:PID'],
40             [
41             'jobs',
42             sub {
43 0           sprintf "%i/%i/%i", scalar @{$_[0]}, $_[1]{status}{jobs},
44 0     0     $_[1]{status}{performed};
45             }
46             ],
47 0     0     ['started', sub { _running_since($now - shift) }, 'STATUS'],
48 0     0     ['status', sub {"@{ $_[0]{queues} }"}, 'QUEUES'],
  0            
  0            
49             ];
50             }
51              
52             1;
53              
54             #pod =encoding utf8
55             #pod
56             #pod =head1 SYNOPSIS
57             #pod
58             #pod Usage: APPLICATION kevin workers [OPTIONS]
59             #pod
60             #pod ./myapp.pl kevin workers
61             #pod ./myapp.pl kevin workers -l 10 -o 20
62             #pod
63             #pod Options:
64             #pod -h, --help Show this summary of available options
65             #pod -l, --limit Number of workers to show when listing
66             #pod them, defaults to 100
67             #pod -o, --offset Number of workers to skip when listing
68             #pod them, defaults to 0
69             #pod
70             #pod =head1 DESCRIPTION
71             #pod
72             #pod L lists workers at a L queue.
73             #pod It produces output as below.
74             #pod
75             #pod ID HOST:PID JOBS STATUS QUEUES
76             #pod 27302 39c7d2ded2c4/dev13.ke.vin:31 0/4/310 Up 2 days image-resizer
77             #pod 27293 e7b1c0a64810/dev12.ke.vin:34 0/4/378 Up 2 days image-resizer
78             #pod 27187 7d7190787c5e/dev12.ke.vin:33 0/4/381 Up 2 days uploader video-uploader
79             #pod 27186 6badf6e19282/dev12.ke.vin:34 0/4/289 Up 2 days uploader video-uploader
80             #pod 27185 59dc9b9752dd/dev12.ke.vin:35 0/4/108 Up 2 days uploader video-uploader
81             #pod 26851 8bd2e06cdbd2/dev13.ke.vin:31 0/4/209 Up 2 days poker
82             #pod 26850 b9d044771a57/dev13.ke.vin:32 0/4/237 Up 11 days poker
83             #pod 26822 f24eaa47795d:6429 0/4/183 Up 2 weeks item-searcher
84             #pod 26748 0fdb4ead83c5:6400 0/4/349 Up 2 weeks item-searcher
85             #pod
86             #pod The entry under C reads as
87             #pod
88             #pod active jobs / capacity / performed jobs
89             #pod
90             #pod =head1 ATTRIBUTES
91             #pod
92             #pod L inherits all attributes from
93             #pod L and implements the following new ones.
94             #pod
95             #pod =head2 description
96             #pod
97             #pod my $description = $command->description;
98             #pod $command = $command->description('Foo');
99             #pod
100             #pod Short description of this command, used for the command list.
101             #pod
102             #pod =head2 usage
103             #pod
104             #pod my $usage = $command->usage;
105             #pod $command = $command->usage('Foo');
106             #pod
107             #pod Usage information for this command, used for the help screen.
108             #pod
109             #pod =head1 METHODS
110             #pod
111             #pod L inherits all methods from
112             #pod L and implements the following new ones.
113             #pod
114             #pod =head2 run
115             #pod
116             #pod $command->run(@ARGV);
117             #pod
118             #pod Run this command.
119             #pod
120             #pod =head1 SEE ALSO
121             #pod
122             #pod L, L.
123             #pod
124             #pod =cut
125              
126             __END__