File Coverage

blib/lib/Kevin/Command/kevin/workers.pm
Criterion Covered Total %
statement 15 31 48.3
branch n/a
condition n/a
subroutine 5 11 45.4
pod 1 1 100.0
total 21 43 48.8


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