| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Beam::Minion; |
|
2
|
|
|
|
|
|
|
our $VERSION = '0.015'; |
|
3
|
|
|
|
|
|
|
# ABSTRACT: A distributed task runner for Beam::Wire containers |
|
4
|
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
#pod =head1 SYNOPSIS |
|
6
|
|
|
|
|
|
|
#pod |
|
7
|
|
|
|
|
|
|
#pod # Command-line interface |
|
8
|
|
|
|
|
|
|
#pod export BEAM_MINION=sqlite://test.db |
|
9
|
|
|
|
|
|
|
#pod beam minion worker |
|
10
|
|
|
|
|
|
|
#pod beam minion run [...] |
|
11
|
|
|
|
|
|
|
#pod beam minion help |
|
12
|
|
|
|
|
|
|
#pod |
|
13
|
|
|
|
|
|
|
#pod # Perl interface |
|
14
|
|
|
|
|
|
|
#pod local $ENV{BEAM_MINION} = 'sqlite://test.db'; |
|
15
|
|
|
|
|
|
|
#pod Beam::Minion->enqueue( $container, $service, \@args, \%opt ); |
|
16
|
|
|
|
|
|
|
#pod |
|
17
|
|
|
|
|
|
|
#pod =head1 DESCRIPTION |
|
18
|
|
|
|
|
|
|
#pod |
|
19
|
|
|
|
|
|
|
#pod L is a distributed task runner. One or more workers are |
|
20
|
|
|
|
|
|
|
#pod created to run tasks, and then each task is sent to a worker to be run. |
|
21
|
|
|
|
|
|
|
#pod Tasks are configured as L objects by L |
|
22
|
|
|
|
|
|
|
#pod container files. |
|
23
|
|
|
|
|
|
|
#pod |
|
24
|
|
|
|
|
|
|
#pod =head1 GETTING STARTED |
|
25
|
|
|
|
|
|
|
#pod |
|
26
|
|
|
|
|
|
|
#pod =head2 Configure Minion |
|
27
|
|
|
|
|
|
|
#pod |
|
28
|
|
|
|
|
|
|
#pod To start running your L jobs, you must first start |
|
29
|
|
|
|
|
|
|
#pod a L worker with the L
|
|
30
|
|
|
|
|
|
|
#pod worker.command|Beam::Minion::Command::worker>. Minion requires |
|
31
|
|
|
|
|
|
|
#pod a database to coordinate workers, and communicates with this database |
|
32
|
|
|
|
|
|
|
#pod using a L. |
|
33
|
|
|
|
|
|
|
#pod |
|
34
|
|
|
|
|
|
|
#pod The supported Minion backends are: |
|
35
|
|
|
|
|
|
|
#pod |
|
36
|
|
|
|
|
|
|
#pod =over |
|
37
|
|
|
|
|
|
|
#pod |
|
38
|
|
|
|
|
|
|
#pod =item * |
|
39
|
|
|
|
|
|
|
#pod |
|
40
|
|
|
|
|
|
|
#pod L - C<< sqlite: >> |
|
41
|
|
|
|
|
|
|
#pod |
|
42
|
|
|
|
|
|
|
#pod =item * |
|
43
|
|
|
|
|
|
|
#pod |
|
44
|
|
|
|
|
|
|
#pod L - C<< postgresql://:@/ >> |
|
45
|
|
|
|
|
|
|
#pod |
|
46
|
|
|
|
|
|
|
#pod =item * |
|
47
|
|
|
|
|
|
|
#pod |
|
48
|
|
|
|
|
|
|
#pod L - C<< mysql://:@/ >> |
|
49
|
|
|
|
|
|
|
#pod |
|
50
|
|
|
|
|
|
|
#pod =item * |
|
51
|
|
|
|
|
|
|
#pod |
|
52
|
|
|
|
|
|
|
#pod L - C<< mongodb://: >> |
|
53
|
|
|
|
|
|
|
#pod |
|
54
|
|
|
|
|
|
|
#pod =back |
|
55
|
|
|
|
|
|
|
#pod |
|
56
|
|
|
|
|
|
|
#pod Once you've picked a database backend, configure the C |
|
57
|
|
|
|
|
|
|
#pod environment variable with the URL. Minion will automatically deploy the |
|
58
|
|
|
|
|
|
|
#pod database tables it needs, so be sure to allow the right permissions (if |
|
59
|
|
|
|
|
|
|
#pod the database has such things). |
|
60
|
|
|
|
|
|
|
#pod |
|
61
|
|
|
|
|
|
|
#pod In order to communicate with Minion workers on other machines, it will |
|
62
|
|
|
|
|
|
|
#pod be necessary to use a database accessible from the network (so, not |
|
63
|
|
|
|
|
|
|
#pod SQLite). |
|
64
|
|
|
|
|
|
|
#pod |
|
65
|
|
|
|
|
|
|
#pod =head2 Start a Worker |
|
66
|
|
|
|
|
|
|
#pod |
|
67
|
|
|
|
|
|
|
#pod Once the C environment variable is set, you can start |
|
68
|
|
|
|
|
|
|
#pod a worker with C<< beam minion worker >>. Each worker can run jobs from |
|
69
|
|
|
|
|
|
|
#pod all the containers it can find from the C environment |
|
70
|
|
|
|
|
|
|
#pod variable. Each worker will run up to 4 jobs concurrently. |
|
71
|
|
|
|
|
|
|
#pod |
|
72
|
|
|
|
|
|
|
#pod =head2 Spawn a Job |
|
73
|
|
|
|
|
|
|
#pod |
|
74
|
|
|
|
|
|
|
#pod Jobs are spawned with C<< beam minion run >>. |
|
75
|
|
|
|
|
|
|
#pod The C must be an object that consumes the L |
|
76
|
|
|
|
|
|
|
#pod role. C should be a path to a container file and can be |
|
77
|
|
|
|
|
|
|
#pod an absolute path, a path relative to the current directory, or a |
|
78
|
|
|
|
|
|
|
#pod path relative to one of the paths in the C environment |
|
79
|
|
|
|
|
|
|
#pod variable (separated by C<:>). |
|
80
|
|
|
|
|
|
|
#pod |
|
81
|
|
|
|
|
|
|
#pod You can queue up jobs before you have workers running. As soon as |
|
82
|
|
|
|
|
|
|
#pod a worker is available, it will start running jobs from the queue. |
|
83
|
|
|
|
|
|
|
#pod |
|
84
|
|
|
|
|
|
|
#pod =head1 SEE ALSO |
|
85
|
|
|
|
|
|
|
#pod |
|
86
|
|
|
|
|
|
|
#pod L, L, L |
|
87
|
|
|
|
|
|
|
#pod |
|
88
|
|
|
|
|
|
|
#pod =cut |
|
89
|
|
|
|
|
|
|
|
|
90
|
1
|
|
|
1
|
|
8
|
use strict; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
32
|
|
|
91
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
32
|
|
|
92
|
1
|
|
|
1
|
|
489
|
use Beam::Minion::Util qw( minion ); |
|
|
1
|
|
|
|
|
8
|
|
|
|
1
|
|
|
|
|
159
|
|
|
93
|
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
#pod =sub enqueue |
|
95
|
|
|
|
|
|
|
#pod |
|
96
|
|
|
|
|
|
|
#pod Beam::Minion->enqueue( $container_name, $task_name, \@args, \%opt ); |
|
97
|
|
|
|
|
|
|
#pod |
|
98
|
|
|
|
|
|
|
#pod Enqueue the task named C<$task_name> from the container named C<$container_name>. |
|
99
|
|
|
|
|
|
|
#pod The C environment variable must be set. |
|
100
|
|
|
|
|
|
|
#pod |
|
101
|
|
|
|
|
|
|
#pod C<\%opt> is a hash reference with the following keys: |
|
102
|
|
|
|
|
|
|
#pod |
|
103
|
|
|
|
|
|
|
#pod =over |
|
104
|
|
|
|
|
|
|
#pod |
|
105
|
|
|
|
|
|
|
#pod =item attempts |
|
106
|
|
|
|
|
|
|
#pod |
|
107
|
|
|
|
|
|
|
#pod Number of times to retry this job if it fails. Defaults to C<1>. |
|
108
|
|
|
|
|
|
|
#pod |
|
109
|
|
|
|
|
|
|
#pod =item delay |
|
110
|
|
|
|
|
|
|
#pod |
|
111
|
|
|
|
|
|
|
#pod Time (in seconds) to delay this job (from now). Defaults to C<0>. |
|
112
|
|
|
|
|
|
|
#pod |
|
113
|
|
|
|
|
|
|
#pod =item priority |
|
114
|
|
|
|
|
|
|
#pod |
|
115
|
|
|
|
|
|
|
#pod The job priority. Higher priority jobs get performed first. Defaults to C<0>. |
|
116
|
|
|
|
|
|
|
#pod |
|
117
|
|
|
|
|
|
|
#pod =back |
|
118
|
|
|
|
|
|
|
#pod |
|
119
|
|
|
|
|
|
|
#pod (These are the same options allowed in L
|
|
120
|
|
|
|
|
|
|
#pod method|http://mojolicious.org/perldoc/Minion#enqueue1>) |
|
121
|
|
|
|
|
|
|
#pod |
|
122
|
|
|
|
|
|
|
#pod =cut |
|
123
|
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
sub enqueue { |
|
125
|
3
|
|
|
3
|
1
|
21
|
my ( $class, $container, $task, $args, $opt ) = @_; |
|
126
|
3
|
|
|
|
|
23
|
my $minion = minion(); |
|
127
|
2
|
|
|
|
|
82749
|
$minion->enqueue( "$container:$task", $args, $opt ); |
|
128
|
|
|
|
|
|
|
} |
|
129
|
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
1; |
|
131
|
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
__END__ |