line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Minion::Task; |
2
|
1
|
|
|
1
|
|
67034
|
use Mojo::Base -base; |
|
1
|
|
|
|
|
191284
|
|
|
1
|
|
|
|
|
7
|
|
3
|
|
|
|
|
|
|
|
4
|
1
|
|
|
1
|
|
774
|
use Mojo::Loader qw(load_class); |
|
1
|
|
|
|
|
35221
|
|
|
1
|
|
|
|
|
65
|
|
5
|
1
|
|
|
1
|
|
527
|
use Mojo::Server; |
|
1
|
|
|
|
|
9734
|
|
|
1
|
|
|
|
|
10
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
our $VERSION = '0.0.1'; |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
has [qw/id parent_id user/]; |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
has 'app' => sub { Mojo::Server->new->build_app('Mojo::HelloWorld') }, weak => 1; |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
has 'args' => sub { {} }; |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
has 'chain' => sub { shift->args->{ chain } || [] }; |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
has 'children' => sub { |
18
|
|
|
|
|
|
|
my $self = shift; |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
my @children = @{ $self->subtasks }; |
21
|
|
|
|
|
|
|
push(@children, @{ $self->chain }); |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
return \@children; |
24
|
|
|
|
|
|
|
}; |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
has 'error' => 'Failed.'; |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
has 'failed' => sub { 0 }; |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
has 'finish' => 'Action complete.'; |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
has 'name' => sub { ref(shift) }; |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
has 'options' => sub { |
35
|
|
|
|
|
|
|
my $self = shift; |
36
|
|
|
|
|
|
|
my $options = { |
37
|
|
|
|
|
|
|
queue => 'default', |
38
|
|
|
|
|
|
|
}; |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
if ($self->parent_id) { |
41
|
|
|
|
|
|
|
$options->{ parents } = [$self->parent_id]; |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
return $options; |
45
|
|
|
|
|
|
|
}; |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
has 'subtasks' => sub { [] }; |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
has 'tags' => sub { |
50
|
|
|
|
|
|
|
my $self = shift; |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
my @tags = map(sprintf("%s %s", $_, $self->args->{ $_ }), sort(keys(%{ $self->args }))); |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
return \@tags; |
55
|
|
|
|
|
|
|
}; |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
=head2 dispatch |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
Dispatch the task |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
=cut |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
sub dispatch { |
65
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
66
|
|
|
|
|
|
|
|
67
|
0
|
|
|
|
|
|
return $self->start; |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
=head2 processChain |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
Process the chain of tasks |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
=cut |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
sub processChain { |
77
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
78
|
|
|
|
|
|
|
|
79
|
0
|
|
|
|
|
|
my @children = @{ $self->children }; |
|
0
|
|
|
|
|
|
|
80
|
0
|
|
|
|
|
|
my $task = shift(@children); |
81
|
|
|
|
|
|
|
|
82
|
0
|
|
|
|
|
|
my $e = load_class($task); |
83
|
|
|
|
|
|
|
|
84
|
0
|
0
|
|
|
|
|
$self->app->fatal("Loading '$task' failed: $e") if ($e); |
85
|
|
|
|
|
|
|
|
86
|
0
|
|
|
|
|
|
$task->new(app => $self->app, args => $self->args, parent_id => $self->id) |
87
|
|
|
|
|
|
|
->withChain(\@children) |
88
|
|
|
|
|
|
|
->dispatch; |
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
=head2 start |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
Start the task |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
=cut |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
sub start { |
98
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
99
|
|
|
|
|
|
|
|
100
|
0
|
|
|
|
|
|
my $ok = $self->run(@_); |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
# When current task was successful, |
103
|
|
|
|
|
|
|
# and there are children tasks defined, |
104
|
|
|
|
|
|
|
# try to process them |
105
|
0
|
0
|
0
|
|
|
|
if ($ok && scalar(@{ $self->children })) { |
|
0
|
|
|
|
|
|
|
106
|
0
|
|
|
|
|
|
$self->processChain; |
107
|
|
|
|
|
|
|
} |
108
|
|
|
|
|
|
|
|
109
|
0
|
|
|
|
|
|
return $ok; |
110
|
|
|
|
|
|
|
} |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
1; |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
=encoding utf8 |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
=head1 NAME |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
Minion::Task - A task boilerplate for Minion |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
=head1 SYNOPSIS |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
package MyApp::Tasks::HelloWorld; |
123
|
|
|
|
|
|
|
use Mojo::Base 'Minion::Task'; |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
... defined your own logic here ... |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
=head1 DESCRIPTION |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
L is a package that provides a way of handling minion tasks |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
=head1 ATTRIBUTES |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
L inherits all attributes from L. |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
=head1 METHODS |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
L inherits all methods from L and implements |
138
|
|
|
|
|
|
|
the following new ones. |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
=head2 dispatch |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
$task->dispatch; |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
Is basically a link to start method. |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
=head2 processChain |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
$task->processChain; |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
If current task has subtasks or if there's something defined in the args->{ chain }, |
151
|
|
|
|
|
|
|
those tasks will be dispatched. |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
=head2 start |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
$task->start; |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
Start processing the task. |
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
=head1 SEE ALSO |
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
L, L, L, L. |
162
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
=cut |