File Coverage

blib/lib/Kevin/Command/kevin/jobs.pm
Criterion Covered Total %
statement 15 27 55.5
branch n/a
condition n/a
subroutine 5 9 55.5
pod 1 1 100.0
total 21 37 56.7


line stmt bran cond sub pod time code
1              
2             package Kevin::Command::kevin::jobs;
3             $Kevin::Command::kevin::jobs::VERSION = '0.4.0';
4             # ABSTRACT: Command to list Minion jobs
5 1     1   38626 use Mojo::Base 'Mojolicious::Command';
  1         4  
  1         13  
6              
7 1     1   562 use Kevin::Commands::Util ();
  1         3  
  1         24  
8 1     1   5 use Mojo::Util qw(getopt);
  1         2  
  1         64  
9 1     1   299 use Text::Yeti::Table qw(render_table);
  1         937  
  1         57  
10 1     1   7 use Time::HiRes qw(time);
  1         2  
  1         10  
11              
12             has description => 'List Minion jobs';
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             getopt \@args,
23             'l|limit=i' => \(my $limit = 100),
24             'o|offset=i' => \(my $offset = 0),
25             'q|queue=s' => \$options->{queue},
26             'S|state=s' => \$options->{state},
27 0           't|task=s' => \$options->{task};
28              
29 0           my $jobs = $minion->backend->list_jobs($offset, $limit, $options);
30              
31 0           my $spec = $self->_table_spec;
32 0           render_table($jobs, $spec);
33             }
34              
35             *_created_since = *Kevin::Commands::Util::_created_since;
36             *_job_status = *Kevin::Commands::Util::_job_status;
37              
38             sub _table_spec {
39              
40 0     0     my $now = time;
41             return [
42             qw(id),
43             ['priority', undef, 'PRI'],
44             qw( task state queue ),
45 0     0     ['created', sub { _created_since($now - shift) }],
46 0     0     ['state', sub { _job_status($_[1], $now) }, 'STATUS'],
  0            
47             qw(worker),
48             ];
49             }
50              
51             1;
52              
53             #pod =encoding utf8
54             #pod
55             #pod =head1 SYNOPSIS
56             #pod
57             #pod Usage: APPLICATION kevin jobs [OPTIONS]
58             #pod
59             #pod ./myapp.pl kevin jobs
60             #pod ./myapp.pl kevin jobs -l 10 -o 20
61             #pod ./myapp.pl kevin jobs -q important -t foo -S inactive
62             #pod
63             #pod Options:
64             #pod -h, --help Show this summary of available options
65             #pod -l, --limit Number of jobs to show when listing
66             #pod them, defaults to 100
67             #pod -o, --offset Number of jobs to skip when listing
68             #pod them, defaults to 0
69             #pod -q, --queue List only jobs in this queue
70             #pod -S, --state List only jobs in this state
71             #pod -t, --task List only jobs for this task
72             #pod
73             #pod =head1 DESCRIPTION
74             #pod
75             #pod L lists jobs at a L queue.
76             #pod It produces output as below.
77             #pod
78             #pod ID PRI TASK STATE QUEUE CREATED STATUS WORKER
79             #pod 925851 0 resize finished image-resizer 7 minutes ago Finished 7 minutes ago 27297
80             #pod 925838 1000 search failed item-searcher 13 minutes ago Failed 13 minutes ago 27191
81             #pod 925835 1000 upload finished uploader 13 minutes ago Finished 13 minutes ago 27185
82             #pod 925832 1000 search finished item-searcher 13 minutes ago Finished 13 minutes ago 27188
83             #pod 925831 100 poke failed poker 13 minutes ago Failed 13 minutes ago 26819
84             #pod 925830 100 poke failed poker 31 hours ago Failed 31 hours ago 26847
85             #pod
86             #pod =head1 ATTRIBUTES
87             #pod
88             #pod L inherits all attributes from
89             #pod L and implements the following new ones.
90             #pod
91             #pod =head2 description
92             #pod
93             #pod my $description = $command->description;
94             #pod $command = $command->description('Foo');
95             #pod
96             #pod Short description of this command, used for the command list.
97             #pod
98             #pod =head2 usage
99             #pod
100             #pod my $usage = $command->usage;
101             #pod $command = $command->usage('Foo');
102             #pod
103             #pod Usage information for this command, used for the help screen.
104             #pod
105             #pod =head1 METHODS
106             #pod
107             #pod L inherits all methods from
108             #pod L and implements the following new ones.
109             #pod
110             #pod =head2 run
111             #pod
112             #pod $command->run(@ARGV);
113             #pod
114             #pod Run this command.
115             #pod
116             #pod =head1 SEE ALSO
117             #pod
118             #pod L, L.
119             #pod
120             #pod =cut
121              
122             __END__