| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Minion::Command::minion::schedule; |
|
2
|
1
|
|
|
1
|
|
19785
|
use Mojo::Base 'Mojolicious::Command'; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
8
|
|
|
3
|
|
|
|
|
|
|
|
|
4
|
1
|
|
|
1
|
|
253
|
use Mojo::JSON qw(decode_json); |
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
54
|
|
|
5
|
1
|
|
|
1
|
|
3
|
use Mojo::Util qw(getopt tablify); |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
655
|
|
|
6
|
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
has description => 'Manage Minion schedules'; |
|
8
|
|
|
|
|
|
|
has usage => sub { shift->extract_usage }; |
|
9
|
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
sub run { |
|
11
|
0
|
|
|
0
|
1
|
|
my ($self, @args) = @_; |
|
12
|
|
|
|
|
|
|
|
|
13
|
0
|
|
|
|
|
|
my ($args, $options) = ([], {}); |
|
14
|
|
|
|
|
|
|
getopt \@args, |
|
15
|
|
|
|
|
|
|
'A|attempts=i' => \$options->{attempts}, |
|
16
|
0
|
|
|
0
|
|
|
'a|args=s' => sub { $args = decode_json($_[1]) }, |
|
17
|
|
|
|
|
|
|
'c|cron=s' => \my $cron, |
|
18
|
|
|
|
|
|
|
'd|dispatch' => \my $dispatch, |
|
19
|
|
|
|
|
|
|
'E|expire=i' => \$options->{expire}, |
|
20
|
|
|
|
|
|
|
'e|enqueue=s' => \my $enqueue, |
|
21
|
|
|
|
|
|
|
'l|limit=i' => \(my $limit = 100), |
|
22
|
0
|
|
|
0
|
|
|
'n|notes=s' => sub { $options->{notes} = decode_json($_[1]) }, |
|
23
|
|
|
|
|
|
|
'o|offset=i' => \(my $offset = 0), |
|
24
|
|
|
|
|
|
|
'P|pause=s' => \my $pause, |
|
25
|
|
|
|
|
|
|
'p|priority=i' => \$options->{priority}, |
|
26
|
|
|
|
|
|
|
'q|queue=s' => \$options->{queue}, |
|
27
|
|
|
|
|
|
|
'R|remove=s' => \my $remove, |
|
28
|
|
|
|
|
|
|
'r|resume=s' => \my $resume, |
|
29
|
|
|
|
|
|
|
't|task=s' => \my $task, |
|
30
|
0
|
|
|
|
|
|
'x|lax=s' => \$options->{lax}; |
|
31
|
|
|
|
|
|
|
|
|
32
|
0
|
|
|
|
|
|
my $minion = $self->app->minion; |
|
33
|
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
# Add or update a schedule |
|
35
|
0
|
0
|
|
|
|
|
if ($enqueue) { |
|
36
|
0
|
0
|
|
|
|
|
die "Cron expression is required (-c).\n" unless defined $cron; |
|
37
|
0
|
0
|
|
|
|
|
die "Task is required (-t).\n" unless defined $task; |
|
38
|
0
|
|
|
|
|
|
return say $minion->schedule($enqueue, $cron, $task, $args, $options); |
|
39
|
|
|
|
|
|
|
} |
|
40
|
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
# Pause, resume or remove |
|
42
|
0
|
0
|
0
|
|
|
|
return $minion->pause_schedule($pause) || die "Schedule does not exist.\n" if $pause; |
|
43
|
0
|
0
|
0
|
|
|
|
return $minion->resume_schedule($resume) || die "Schedule does not exist.\n" if $resume; |
|
44
|
0
|
0
|
0
|
|
|
|
return $minion->unschedule($remove) || die "Schedule does not exist.\n" if $remove; |
|
45
|
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
# Manually dispatch any due schedules |
|
47
|
0
|
0
|
|
|
|
|
return print Minion::_dump($minion->dispatch_schedules) if $dispatch; |
|
48
|
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
# Schedule info |
|
50
|
0
|
|
|
|
|
|
my $name = shift @args; |
|
51
|
0
|
0
|
|
|
|
|
if (defined $name) { |
|
52
|
|
|
|
|
|
|
die "Schedule does not exist.\n" |
|
53
|
0
|
0
|
|
|
|
|
unless my $info = $minion->list_schedules(0, 1, {names => [$name]})->{schedules}[0]; |
|
54
|
0
|
|
|
|
|
|
return print Minion::_dump(Minion::_datetime($info)); |
|
55
|
|
|
|
|
|
|
} |
|
56
|
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
# List schedules |
|
58
|
0
|
|
|
|
|
|
$self->_list($offset, $limit); |
|
59
|
|
|
|
|
|
|
} |
|
60
|
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
sub _list { |
|
62
|
0
|
|
|
0
|
|
|
my ($self, $offset, $limit) = @_; |
|
63
|
0
|
|
|
|
|
|
my $schedules = $self->app->minion->list_schedules($offset, $limit)->{schedules}; |
|
64
|
0
|
|
|
|
|
|
@$schedules = map { Minion::_datetime($_) } @$schedules; |
|
|
0
|
|
|
|
|
|
|
|
65
|
0
|
|
|
|
|
|
print tablify [map { [@$_{qw(id name task cron next_run paused)}] } @$schedules]; |
|
|
0
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
} |
|
67
|
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
1; |
|
69
|
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
=encoding utf8 |
|
71
|
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
=head1 NAME |
|
73
|
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
Minion::Command::minion::schedule - Minion schedule command |
|
75
|
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
77
|
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
Usage: APPLICATION minion schedule [OPTIONS] [NAME] |
|
79
|
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
./myapp.pl minion schedule |
|
81
|
|
|
|
|
|
|
./myapp.pl minion schedule daily |
|
82
|
|
|
|
|
|
|
./myapp.pl minion schedule -e daily -c '0 4 * * *' -t cleanup |
|
83
|
|
|
|
|
|
|
./myapp.pl minion schedule -e foo -c '*/5 * * * *' -t bar -a '[1, 2, 3]' -p 5 -q important |
|
84
|
|
|
|
|
|
|
./myapp.pl minion schedule -e weekday_report -c '0 9 * * 1-5' -t report -A 3 |
|
85
|
|
|
|
|
|
|
./myapp.pl minion schedule -P daily |
|
86
|
|
|
|
|
|
|
./myapp.pl minion schedule -r daily |
|
87
|
|
|
|
|
|
|
./myapp.pl minion schedule -R daily |
|
88
|
|
|
|
|
|
|
./myapp.pl minion schedule -d |
|
89
|
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
Options: |
|
91
|
|
|
|
|
|
|
-A, --attempts Number of times each enqueued job will be |
|
92
|
|
|
|
|
|
|
attempted, defaults to 1 |
|
93
|
|
|
|
|
|
|
-a, --args Arguments for the new schedule in JSON format |
|
94
|
|
|
|
|
|
|
-c, --cron Cron expression for new schedule |
|
95
|
|
|
|
|
|
|
-d, --dispatch Manually dispatch any due schedules |
|
96
|
|
|
|
|
|
|
-E, --expire Each enqueued job is valid for this many seconds |
|
97
|
|
|
|
|
|
|
before it expires |
|
98
|
|
|
|
|
|
|
-e, --enqueue Add or replace a schedule with this name |
|
99
|
|
|
|
|
|
|
(requires -c and -t) |
|
100
|
|
|
|
|
|
|
-h, --help Show this summary of available options |
|
101
|
|
|
|
|
|
|
--home Path to home directory of your application, |
|
102
|
|
|
|
|
|
|
defaults to the value of MOJO_HOME or |
|
103
|
|
|
|
|
|
|
auto-detection |
|
104
|
|
|
|
|
|
|
-l, --limit Number of schedules to show when listing them, |
|
105
|
|
|
|
|
|
|
defaults to 100 |
|
106
|
|
|
|
|
|
|
-m, --mode Operating mode for your application, defaults to |
|
107
|
|
|
|
|
|
|
the value of MOJO_MODE/PLACK_ENV or |
|
108
|
|
|
|
|
|
|
"development" |
|
109
|
|
|
|
|
|
|
-n, --notes Notes in JSON format for the new schedule |
|
110
|
|
|
|
|
|
|
-o, --offset Number of schedules to skip when listing them, |
|
111
|
|
|
|
|
|
|
defaults to 0 |
|
112
|
|
|
|
|
|
|
-P, --pause Pause a schedule |
|
113
|
|
|
|
|
|
|
-p, --priority Priority of each enqueued job |
|
114
|
|
|
|
|
|
|
-q, --queue Queue to put each enqueued job in, defaults to |
|
115
|
|
|
|
|
|
|
"default" |
|
116
|
|
|
|
|
|
|
-R, --remove Remove a schedule |
|
117
|
|
|
|
|
|
|
-r, --resume Resume a paused schedule |
|
118
|
|
|
|
|
|
|
-t, --task Task name for the new schedule |
|
119
|
|
|
|
|
|
|
-x, --lax Existing jobs each enqueued job depends on may |
|
120
|
|
|
|
|
|
|
also have failed to allow for it to be processed |
|
121
|
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
123
|
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
L manages L schedules. |
|
125
|
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
=head1 ATTRIBUTES |
|
127
|
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
L inherits all attributes from L and implements the following |
|
129
|
|
|
|
|
|
|
new ones. |
|
130
|
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
=head2 description |
|
132
|
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
my $description = $schedule->description; |
|
134
|
|
|
|
|
|
|
$schedule = $schedule->description('Foo'); |
|
135
|
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
Short description of this command, used for the command list. |
|
137
|
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
=head2 usage |
|
139
|
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
my $usage = $schedule->usage; |
|
141
|
|
|
|
|
|
|
$schedule = $schedule->usage('Foo'); |
|
142
|
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
Usage information for this command, used for the help screen. |
|
144
|
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
=head1 METHODS |
|
146
|
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
L inherits all methods from L and implements the following new |
|
148
|
|
|
|
|
|
|
ones. |
|
149
|
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
=head2 run |
|
151
|
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
$schedule->run(@ARGV); |
|
153
|
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
Run this command. |
|
155
|
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
=head1 SEE ALSO |
|
157
|
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
L, L, L, L, L. |
|
159
|
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
=cut |