line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Gearman::Job; |
2
|
12
|
|
|
12
|
|
2424
|
use version (); |
|
12
|
|
|
|
|
1696
|
|
|
12
|
|
|
|
|
488
|
|
3
|
|
|
|
|
|
|
$Gearman::Job::VERSION = version->declare("2.002.002"); #TRIAL |
4
|
|
|
|
|
|
|
|
5
|
12
|
|
|
12
|
|
48
|
use strict; |
|
12
|
|
|
|
|
16
|
|
|
12
|
|
|
|
|
249
|
|
6
|
12
|
|
|
12
|
|
43
|
use warnings; |
|
12
|
|
|
|
|
22
|
|
|
12
|
|
|
|
|
330
|
|
7
|
|
|
|
|
|
|
|
8
|
12
|
|
|
12
|
|
440
|
use Gearman::Util (); |
|
12
|
|
|
|
|
17
|
|
|
12
|
|
|
|
|
185
|
|
9
|
12
|
|
|
12
|
|
46
|
use Carp (); |
|
12
|
|
|
|
|
15
|
|
|
12
|
|
|
|
|
243
|
|
10
|
12
|
|
|
|
|
761
|
use Ref::Util qw/ |
11
|
|
|
|
|
|
|
is_plain_scalarref |
12
|
|
|
|
|
|
|
is_ref |
13
|
12
|
|
|
12
|
|
671
|
/; |
|
12
|
|
|
|
|
639
|
|
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
=head1 NAME |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
Gearman::Job - Job in gearman distributed job system |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
=head1 DESCRIPTION |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
I is the object that's handed to the worker subrefs |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
=head1 METHODS |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
=cut |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
use fields ( |
29
|
12
|
|
|
|
|
82
|
'func', |
30
|
|
|
|
|
|
|
'argref', |
31
|
|
|
|
|
|
|
'handle', |
32
|
|
|
|
|
|
|
'jss', # job server's socket |
33
|
12
|
|
|
12
|
|
555
|
); |
|
12
|
|
|
|
|
1294
|
|
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
sub new { |
36
|
1
|
|
|
1
|
0
|
1265
|
my ($self, $func, $argref, $handle, $jss) = @_; |
37
|
1
|
50
|
|
|
|
11
|
unless (is_ref($self)) { |
38
|
1
|
|
|
|
|
3
|
$self = fields::new($self); |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
|
41
|
1
|
|
|
|
|
3058
|
$self->{func} = $func; |
42
|
1
|
|
|
|
|
2
|
$self->{handle} = $handle; |
43
|
1
|
|
|
|
|
2
|
$self->{argref} = $argref; |
44
|
1
|
|
|
|
|
1
|
$self->{jss} = $jss; |
45
|
1
|
|
|
|
|
3
|
return $self; |
46
|
|
|
|
|
|
|
} ## end sub new |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
=head2 set_status($numerator, $denominator) |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
Updates the status of the job (most likely, a long-running job) and sends |
51
|
|
|
|
|
|
|
it back to the job server. I<$numerator> and I<$denominator> should |
52
|
|
|
|
|
|
|
represent the percentage completion of the job. |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
=cut |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
sub set_status { |
57
|
1
|
|
|
1
|
1
|
458
|
my $self = shift; |
58
|
1
|
|
|
|
|
2
|
my ($nu, $de) = @_; |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
my $req = Gearman::Util::pack_req_command("work_status", |
61
|
1
|
|
|
|
|
16
|
join("\0", $self->{handle}, $nu, $de)); |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
Carp::croak "work_status write failed" |
64
|
1
|
0
|
|
|
|
4
|
unless Gearman::Util::send_req($self->{jss}, \$req); |
65
|
|
|
|
|
|
|
|
66
|
0
|
|
|
|
|
0
|
return 1; |
67
|
|
|
|
|
|
|
} ## end sub set_status |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
=head2 argref() |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
=cut |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
sub argref { |
74
|
1
|
|
|
1
|
1
|
16
|
my $self = shift; |
75
|
1
|
|
|
|
|
5
|
return $self->{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
|
my $self = shift; |
86
|
1
|
|
|
|
|
2
|
return ${ $self->{argref} }; |
|
1
|
|
|
|
|
2
|
|
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
=head2 handle() |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
B handle |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
=cut |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
sub handle { |
96
|
1
|
|
|
1
|
1
|
478
|
my $self = shift; |
97
|
1
|
|
|
|
|
5
|
return $self->{handle}; |
98
|
|
|
|
|
|
|
} |
99
|
|
|
|
|
|
|
|