line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Gearman::Job; |
2
|
12
|
|
|
12
|
|
2158
|
use version (); |
|
12
|
|
|
|
|
1308
|
|
|
12
|
|
|
|
|
412
|
|
3
|
|
|
|
|
|
|
$Gearman::Job::VERSION = version->declare("2.003_002"); |
4
|
|
|
|
|
|
|
|
5
|
12
|
|
|
12
|
|
69
|
use strict; |
|
12
|
|
|
|
|
15
|
|
|
12
|
|
|
|
|
211
|
|
6
|
12
|
|
|
12
|
|
36
|
use warnings; |
|
12
|
|
|
|
|
11
|
|
|
12
|
|
|
|
|
267
|
|
7
|
|
|
|
|
|
|
|
8
|
12
|
|
|
12
|
|
356
|
use Gearman::Util (); |
|
12
|
|
|
|
|
15
|
|
|
12
|
|
|
|
|
162
|
|
9
|
12
|
|
|
12
|
|
35
|
use Carp (); |
|
12
|
|
|
|
|
14
|
|
|
12
|
|
|
|
|
245
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
=head1 NAME |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
Gearman::Job - Job in gearman distributed job system |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
=head1 DESCRIPTION |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
I is the object that's handed to the worker subrefs |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
=head1 METHODS |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
=cut |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
use fields ( |
25
|
12
|
|
|
|
|
66
|
'func', |
26
|
|
|
|
|
|
|
'argref', |
27
|
|
|
|
|
|
|
'handle', |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
# job server's socket |
30
|
|
|
|
|
|
|
'jss', |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
# job server |
33
|
|
|
|
|
|
|
'js', |
34
|
12
|
|
|
12
|
|
588
|
); |
|
12
|
|
|
|
|
1011
|
|
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
sub new { |
37
|
1
|
|
|
1
|
0
|
660
|
my ($self, %arg) = @_; |
38
|
1
|
50
|
|
|
|
5
|
unless (ref $self) { |
39
|
1
|
|
|
|
|
5
|
$self = fields::new($self); |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
|
42
|
1
|
|
|
|
|
2544
|
while(my ($k, $v) = each(%arg)) { |
43
|
5
|
|
|
|
|
11
|
$self->{$k} = $v; |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
|
46
|
1
|
|
|
|
|
3
|
return $self; |
47
|
|
|
|
|
|
|
} ## end sub new |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
=head2 set_status($numerator, $denominator) |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
Updates the status of the job (most likely, a long-running job) and sends |
52
|
|
|
|
|
|
|
it back to the job server. I<$numerator> and I<$denominator> should |
53
|
|
|
|
|
|
|
represent the percentage completion of the job. |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
=cut |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
sub set_status { |
58
|
1
|
|
|
1
|
1
|
716
|
my $self = shift; |
59
|
1
|
|
|
|
|
13
|
my ($nu, $de) = @_; |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
my $req = Gearman::Util::pack_req_command("work_status", |
62
|
1
|
|
|
|
|
4
|
join("\0", $self->{handle}, $nu, $de)); |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
Carp::croak "work_status write failed" |
65
|
1
|
0
|
|
|
|
3
|
unless Gearman::Util::send_req($self->{jss}, \$req); |
66
|
|
|
|
|
|
|
|
67
|
0
|
|
|
|
|
0
|
return 1; |
68
|
|
|
|
|
|
|
} ## end sub set_status |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
=head2 argref() |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
=cut |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
sub argref { |
75
|
1
|
|
|
1
|
1
|
5
|
return shift->{argref}; |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
=head2 arg() |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
B the scalar argument that the client sent to the job server. |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
=cut |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
sub arg { |
85
|
1
|
|
|
1
|
1
|
2
|
return ${ shift->{argref} }; |
|
1
|
|
|
|
|
3
|
|
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
=head2 handle() |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
B handle |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
=cut |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
sub handle { |
95
|
1
|
|
|
1
|
1
|
262
|
return shift->{handle}; |
96
|
|
|
|
|
|
|
} |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
1; |