line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Gearman::Job; |
2
|
12
|
|
|
12
|
|
1943
|
use version (); |
|
12
|
|
|
|
|
1294
|
|
|
12
|
|
|
|
|
414
|
|
3
|
|
|
|
|
|
|
$Gearman::Job::VERSION = version->declare("2.003_001"); |
4
|
|
|
|
|
|
|
|
5
|
12
|
|
|
12
|
|
64
|
use strict; |
|
12
|
|
|
|
|
16
|
|
|
12
|
|
|
|
|
226
|
|
6
|
12
|
|
|
12
|
|
41
|
use warnings; |
|
12
|
|
|
|
|
12
|
|
|
12
|
|
|
|
|
306
|
|
7
|
|
|
|
|
|
|
|
8
|
12
|
|
|
12
|
|
360
|
use Gearman::Util (); |
|
12
|
|
|
|
|
12
|
|
|
12
|
|
|
|
|
271
|
|
9
|
12
|
|
|
12
|
|
40
|
use Carp (); |
|
12
|
|
|
|
|
13
|
|
|
12
|
|
|
|
|
275
|
|
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
|
|
|
|
|
77
|
'func', |
26
|
|
|
|
|
|
|
'argref', |
27
|
|
|
|
|
|
|
'handle', |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
# job server's socket |
30
|
|
|
|
|
|
|
'jss', |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
# job server |
33
|
|
|
|
|
|
|
'js', |
34
|
12
|
|
|
12
|
|
562
|
); |
|
12
|
|
|
|
|
992
|
|
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
sub new { |
37
|
1
|
|
|
1
|
0
|
867
|
my ($self, %arg) = @_; |
38
|
1
|
50
|
|
|
|
6
|
unless (ref $self) { |
39
|
1
|
|
|
|
|
5
|
$self = fields::new($self); |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
|
42
|
1
|
|
|
|
|
2514
|
while(my ($k, $v) = each(%arg)) { |
43
|
5
|
|
|
|
|
10
|
$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
|
799
|
my $self = shift; |
59
|
1
|
|
|
|
|
18
|
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
|
|
|
|
4
|
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
|
|
|
|
|
2
|
|
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
=head2 handle() |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
B handle |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
=cut |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
sub handle { |
95
|
1
|
|
|
1
|
1
|
260
|
return shift->{handle}; |
96
|
|
|
|
|
|
|
} |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
1; |