line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Gearman::Driver::Job::Method; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
1634
|
use Moose; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
=head1 NAME |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
Gearman::Driver::Job::Method - Wraps a single job method |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
=head1 DESCRIPTION |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
=head1 ATTRIBUTES |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
=head2 name |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
Name of the job method. |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
=cut |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
has 'name' => ( |
20
|
|
|
|
|
|
|
is => 'rw', |
21
|
|
|
|
|
|
|
isa => 'Str', |
22
|
|
|
|
|
|
|
required => 1, |
23
|
|
|
|
|
|
|
); |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
=head2 body |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
Code reference which is called by L<Gearman::XS::Worker>. |
28
|
|
|
|
|
|
|
Actually it's not called directly by it, but in a wrapped coderef. |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
=cut |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
has 'body' => ( |
33
|
|
|
|
|
|
|
is => 'rw', |
34
|
|
|
|
|
|
|
isa => 'CodeRef', |
35
|
|
|
|
|
|
|
required => 1, |
36
|
|
|
|
|
|
|
); |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
=head2 worker |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
Reference to the worker object. |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
=cut |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
has 'worker' => ( |
45
|
|
|
|
|
|
|
is => 'rw', |
46
|
|
|
|
|
|
|
isa => 'Any', |
47
|
|
|
|
|
|
|
required => 1, |
48
|
|
|
|
|
|
|
); |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
=head2 encode |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
This may be set to a method name which is implemented in the worker |
53
|
|
|
|
|
|
|
class or any subclass. If the method is not available, it will fail. |
54
|
|
|
|
|
|
|
The returned value of the job method is passed to this method and |
55
|
|
|
|
|
|
|
the return value of this method is sent back to the Gearman server. |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
See also: L<Gearman::Driver::Worker/Encode>. |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
=cut |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
has 'encode' => ( |
62
|
|
|
|
|
|
|
default => '', |
63
|
|
|
|
|
|
|
is => 'rw', |
64
|
|
|
|
|
|
|
isa => 'Str', |
65
|
|
|
|
|
|
|
required => 1, |
66
|
|
|
|
|
|
|
); |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
=head2 decode |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
This may be set to a method name which is implemented in the worker |
71
|
|
|
|
|
|
|
class or any subclass. If the method is not available, it will fail. |
72
|
|
|
|
|
|
|
The workload from L<Gearman::XS::Job> is passed to this method and |
73
|
|
|
|
|
|
|
the return value is passed as argument C<$workload> to the job |
74
|
|
|
|
|
|
|
method. |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
See also: L<Gearman::Driver::Worker/Decode>. |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
=cut |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
has 'decode' => ( |
81
|
|
|
|
|
|
|
default => '', |
82
|
|
|
|
|
|
|
is => 'rw', |
83
|
|
|
|
|
|
|
isa => 'Str', |
84
|
|
|
|
|
|
|
required => 1, |
85
|
|
|
|
|
|
|
); |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
has 'wrapper' => ( |
88
|
|
|
|
|
|
|
is => 'rw', |
89
|
|
|
|
|
|
|
isa => 'CodeRef', |
90
|
|
|
|
|
|
|
); |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
sub BUILD { |
93
|
|
|
|
|
|
|
my ($self) = @_; |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
my $decoder = sub { shift }; |
96
|
|
|
|
|
|
|
my $encoder = sub { shift }; |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
if ( my $decoder_method = $self->decode ) { |
99
|
|
|
|
|
|
|
$decoder = sub { return $self->worker->$decoder_method(@_) }; |
100
|
|
|
|
|
|
|
} |
101
|
|
|
|
|
|
|
if ( my $encoder_method = $self->encode ) { |
102
|
|
|
|
|
|
|
$encoder = sub { return $self->worker->$encoder_method(@_) }; |
103
|
|
|
|
|
|
|
} |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
$self->wrapper( |
106
|
|
|
|
|
|
|
sub { |
107
|
|
|
|
|
|
|
my ($job) = @_; |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
my @args = ($job); |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
push @args, $decoder->( $job->workload ); |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
$self->worker->begin(@args); |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
my $error; |
116
|
|
|
|
|
|
|
my $result; |
117
|
|
|
|
|
|
|
eval { $result = $self->body->( $self->worker, @args ); }; |
118
|
|
|
|
|
|
|
if ($@) { |
119
|
|
|
|
|
|
|
$error = $@; |
120
|
|
|
|
|
|
|
printf "lasterror %d\n", time; |
121
|
|
|
|
|
|
|
printf "lasterror_msg %s\n", $error; |
122
|
|
|
|
|
|
|
$self->worker->on_exception( @args, $error ); |
123
|
|
|
|
|
|
|
} |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
printf "lastrun %d\n", time; |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
$self->worker->end(@args, $error); |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
die $error if $error; |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
return $encoder->($result); |
132
|
|
|
|
|
|
|
} |
133
|
|
|
|
|
|
|
); |
134
|
|
|
|
|
|
|
} |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
=head1 AUTHOR |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
See L<Gearman::Driver>. |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
See L<Gearman::Driver>. |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
=head1 SEE ALSO |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
=over 4 |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
=item * L<Gearman::Driver> |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
=item * L<Gearman::Driver::Adaptor> |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
=item * L<Gearman::Driver::Console> |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
=item * L<Gearman::Driver::Console::Basic> |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
=item * L<Gearman::Driver::Console::Client> |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
=item * L<Gearman::Driver::Job> |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
=item * L<Gearman::Driver::Loader> |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
=item * L<Gearman::Driver::Observer> |
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
=item * L<Gearman::Driver::Worker> |
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
=back |
167
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
=cut |
169
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
1; |