| 1 | package Minion::Command::minion::schedule; | ||||||||||||||||||||
| 2 | 1 | ▶ | use Mojo::Base 'Mojolicious::Command'; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 3 | |||||||||||||||||||||
| 4 | 1 | ▶ | use Mojo::JSON qw(decode_json); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 5 | 1 | ▶ | use Mojo::Util qw(getopt tablify); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 6 | |||||||||||||||||||||
| 7 | 1 | has description => 'Manage Minion schedules'; | |||||||||||||||||||
| 8 | 1 | ▶ | has usage => sub { shift->extract_usage }; | ||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 9 | |||||||||||||||||||||
| 10 | 0 | ▶ | sub run { | ||||||||||||||||||
|
Subroutine
run: not called CC=13 SCAR=52.0
Pod
documented
| |||||||||||||||||||||
| 11 | 0 | my ($self, @args) = @_; | |||||||||||||||||||
| 12 | |||||||||||||||||||||
| 13 | 0 | my ($args, $options) = ([], {}); | |||||||||||||||||||
| 14 | getopt \@args, | ||||||||||||||||||||
| 15 | 'A|attempts=i' => \$options->{attempts}, | ||||||||||||||||||||
| 16 | 0 | ▶ | 'a|args=s' => sub { $args = decode_json($_[1]) }, | ||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||
| 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 | ▶ | 'n|notes=s' => sub { $options->{notes} = decode_json($_[1]) }, | ||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||
| 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 | ▶ | if ($enqueue) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 36 | 0 | ▶ | die "Cron expression is required (-c).\n" unless defined $cron; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 37 | 0 | ▶ | die "Task is required (-t).\n" unless defined $task; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 38 | 0 | return say $minion->schedule($enqueue, $cron, $task, $args, $options); | |||||||||||||||||||
| 39 | } | ||||||||||||||||||||
| 40 | |||||||||||||||||||||
| 41 | # Pause, resume or remove | ||||||||||||||||||||
| 42 | 0 | ▶ | return $minion->pause_schedule($pause) || die "Schedule does not exist.\n" if $pause; | ||||||||||||||||||
|
Branch: 1 branch
Condition0%0/2
$minion->pause_schedule($pause) || die("Schedule does not exist.\n")
MC/DC0%0/1
$minion->pause_schedule($pause) || die("Schedule does not exist.\n")
$minion->pause_schedule($pause)
Truth table0%0/2
A
A= $minion->pause_schedule($pause)
| |||||||||||||||||||||
| 43 | 0 | ▶ | return $minion->resume_schedule($resume) || die "Schedule does not exist.\n" if $resume; | ||||||||||||||||||
|
Branch: 1 branch
Condition0%0/2
$minion->resume_schedule($resume) || die("Schedule does not exist.\n")
MC/DC0%0/1
$minion->resume_schedule($resume) || die("Schedule does not exist.\n")
$minion->resume_schedule($resume)
Truth table0%0/2
A
A= $minion->resume_schedule($resume)
| |||||||||||||||||||||
| 44 | 0 | ▶ | return $minion->unschedule($remove) || die "Schedule does not exist.\n" if $remove; | ||||||||||||||||||
|
Branch: 1 branch
Condition0%0/2
$minion->unschedule($remove) || die("Schedule does not exist.\n")
MC/DC0%0/1
$minion->unschedule($remove) || die("Schedule does not exist.\n")
$minion->unschedule($remove)
Truth table0%0/2
A
A= $minion->unschedule($remove)
| |||||||||||||||||||||
| 45 | |||||||||||||||||||||
| 46 | # Manually dispatch any due schedules | ||||||||||||||||||||
| 47 | 0 | ▶ | return print Minion::_dump($minion->dispatch_schedules) if $dispatch; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 48 | |||||||||||||||||||||
| 49 | # Schedule info | ||||||||||||||||||||
| 50 | 0 | my $name = shift @args; | |||||||||||||||||||
| 51 | 0 | ▶ | if (defined $name) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 52 | die "Schedule does not exist.\n" | ||||||||||||||||||||
| 53 | 0 | ▶ | unless my $info = $minion->list_schedules(0, 1, {names => [$name]})->{schedules}[0]; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 54 | 0 | return print Minion::_dump(Minion::_datetime($info)); | |||||||||||||||||||
| 55 | } | ||||||||||||||||||||
| 56 | |||||||||||||||||||||
| 57 | # List schedules | ||||||||||||||||||||
| 58 | 0 | $self->_list($offset, $limit); | |||||||||||||||||||
| 59 | } | ||||||||||||||||||||
| 60 | |||||||||||||||||||||
| 61 | 0 | ▶ | sub _list { | ||||||||||||||||||
|
Subroutine
_list: not called CC=1 SCAR=6.9
| |||||||||||||||||||||
| 62 | 0 | my ($self, $offset, $limit) = @_; | |||||||||||||||||||
| 63 | 0 | my $schedules = $self->app->minion->list_schedules($offset, $limit)->{schedules}; | |||||||||||||||||||
| 64 | 0 | @$schedules = map { Minion::_datetime($_) } @$schedules; | |||||||||||||||||||
| 65 | 0 | print tablify [map { [@$_{qw(id name task cron next_run paused)}] } @$schedules]; | |||||||||||||||||||
| 66 | } | ||||||||||||||||||||
| 67 | |||||||||||||||||||||
| 68 | 1 | 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> Number of times each enqueued job will be | ||||||||||||||||||||
| 92 | attempted, defaults to 1 | ||||||||||||||||||||
| 93 | -a, --args <JSON array> Arguments for the new schedule in JSON format | ||||||||||||||||||||
| 94 | -c, --cron <expression> Cron expression for new schedule | ||||||||||||||||||||
| 95 | -d, --dispatch Manually dispatch any due schedules | ||||||||||||||||||||
| 96 | -E, --expire <seconds> Each enqueued job is valid for this many seconds | ||||||||||||||||||||
| 97 | before it expires | ||||||||||||||||||||
| 98 | -e, --enqueue <name> 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> Path to home directory of your application, | ||||||||||||||||||||
| 102 | defaults to the value of MOJO_HOME or | ||||||||||||||||||||
| 103 | auto-detection | ||||||||||||||||||||
| 104 | -l, --limit <number> Number of schedules to show when listing them, | ||||||||||||||||||||
| 105 | defaults to 100 | ||||||||||||||||||||
| 106 | -m, --mode <name> Operating mode for your application, defaults to | ||||||||||||||||||||
| 107 | the value of MOJO_MODE/PLACK_ENV or | ||||||||||||||||||||
| 108 | "development" | ||||||||||||||||||||
| 109 | -n, --notes <JSON> Notes in JSON format for the new schedule | ||||||||||||||||||||
| 110 | -o, --offset <number> Number of schedules to skip when listing them, | ||||||||||||||||||||
| 111 | defaults to 0 | ||||||||||||||||||||
| 112 | -P, --pause <name> Pause a schedule | ||||||||||||||||||||
| 113 | -p, --priority <number> Priority of each enqueued job | ||||||||||||||||||||
| 114 | -q, --queue <name> Queue to put each enqueued job in, defaults to | ||||||||||||||||||||
| 115 | "default" | ||||||||||||||||||||
| 116 | -R, --remove <name> Remove a schedule | ||||||||||||||||||||
| 117 | -r, --resume <name> Resume a paused schedule | ||||||||||||||||||||
| 118 | -t, --task <name> Task name for the new schedule | ||||||||||||||||||||
| 119 | -x, --lax <bool> 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<Minion::Command::minion::schedule> manages L<Minion> schedules. | ||||||||||||||||||||
| 125 | |||||||||||||||||||||
| 126 | =head1 ATTRIBUTES | ||||||||||||||||||||
| 127 | |||||||||||||||||||||
| 128 | L<Minion::Command::minion::schedule> inherits all attributes from L<Mojolicious::Command> 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<Minion::Command::minion::schedule> inherits all methods from L<Mojolicious::Command> 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<Minion>, L<Minion::Guide>, L<https://minion.pm>, L<Mojolicious::Guides>, L<https://mojolicious.org>. | ||||||||||||||||||||
| 159 | |||||||||||||||||||||
| 160 | =cut | ||||||||||||||||||||