Minion.pm

filter: Statementstmt 100% 14 / 14 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 4 / 4 Podpod 100% 1 / 1 totaltotal 100% 19 / 19 SCAR 0.0
CC
1
Cov
100%
BEGIN
1.0
BEGIN
1.0
BEGIN
1.0
CRAP 1.0
« Minion/Command/worker.pm ↑ Summary
1 package Beam::Minion;
2 3 our $VERSION = '0.016';
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 <container> <service> [<args>...]
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<Beam::Minion> 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<Beam::Runnable> objects by L<Beam::Wire>
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<Beam::Runner> jobs, you must first start
29 #pod a L<Minion> worker with the L<beam minion
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<Minion::Backend>.
33 #pod
34 #pod The supported Minion backends are:
35 #pod
36 #pod =over
37 #pod
38 #pod =item *
39 #pod
40 #pod L<Minion::Backend::SQLite> - C<< sqlite:<db_path> >>
41 #pod
42 #pod =item *
43 #pod
44 #pod L<Minion::Backend::Pg> - C<< postgresql://<user>:<pass>@<host>/<database> >>
45 #pod
46 #pod =item *
47 #pod
48 #pod L<Minion::Backend::mysql> - C<< mysql://<user>:<pass>@<host>/<database> >>
49 #pod
50 #pod =item *
51 #pod
52 #pod L<Minion::Backend::MongoDB> - C<< mongodb://<host>:<port> >>
53 #pod
54 #pod =back
55 #pod
56 #pod Once you've picked a database backend, configure the C<BEAM_MINION>
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<BEAM_MINION> 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<BEAM_PATH> 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 <container> <service> >>.
75 #pod The C<service> must be an object that consumes the L<Beam::Runnable>
76 #pod role. C<container> 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<BEAM_PATH> 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<Beam::Wire>, L<Beam::Runner>, L<Minion>
87 #pod
88 #pod =cut
89  
90 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
91 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
92 3 ▶use Beam::Minion::Util qw( minion );
Subroutine BEGIN: called CC=1 SCAR=0.0
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<BEAM_MINION> 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<the Minion "enqueue"
120 #pod method|http://mojolicious.org/perldoc/Minion#enqueue1>)
121 #pod
122 #pod =cut
123  
124 sub enqueue {
125 3 ▶ my ( $class, $container, $task, $args, $opt ) = @_;
Subroutine enqueue: called CC=1 SCAR=0.0
Pod documented
126 3 my $minion = minion();
127 2 $minion->enqueue( "$container:$task", $args, $opt );
128 }
129  
130 3 1;
131  
132 __END__
« Minion/Command/worker.pm ↑ Summary