line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Gearman::Job; |
2
|
12
|
|
|
12
|
|
2079
|
use version; |
|
12
|
|
|
|
|
1302
|
|
|
12
|
|
|
|
|
48
|
|
3
|
|
|
|
|
|
|
$Gearman::Job::VERSION = qv("2.001_001"); |
4
|
|
|
|
|
|
|
|
5
|
12
|
|
|
12
|
|
684
|
use strict; |
|
12
|
|
|
|
|
12
|
|
|
12
|
|
|
|
|
171
|
|
6
|
12
|
|
|
12
|
|
35
|
use warnings; |
|
12
|
|
|
|
|
11
|
|
|
12
|
|
|
|
|
209
|
|
7
|
|
|
|
|
|
|
|
8
|
12
|
|
|
12
|
|
405
|
use Gearman::Util (); |
|
12
|
|
|
|
|
13
|
|
|
12
|
|
|
|
|
120
|
|
9
|
12
|
|
|
12
|
|
31
|
use Carp (); |
|
12
|
|
|
|
|
12
|
|
|
12
|
|
|
|
|
199
|
|
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
|
|
|
|
|
42
|
'func', |
26
|
|
|
|
|
|
|
'argref', |
27
|
|
|
|
|
|
|
'handle', |
28
|
|
|
|
|
|
|
'jss', # job server's socket |
29
|
12
|
|
|
12
|
|
433
|
); |
|
12
|
|
|
|
|
987
|
|
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
sub new { |
32
|
1
|
|
|
1
|
0
|
1027
|
my ($class, $func, $argref, $handle, $jss) = @_; |
33
|
1
|
|
|
|
|
1
|
my $self = $class; |
34
|
1
|
50
|
|
|
|
6
|
$self = fields::new($class) unless ref $self; |
35
|
|
|
|
|
|
|
|
36
|
1
|
|
|
|
|
2327
|
$self->{func} = $func; |
37
|
1
|
|
|
|
|
1
|
$self->{handle} = $handle; |
38
|
1
|
|
|
|
|
1
|
$self->{argref} = $argref; |
39
|
1
|
|
|
|
|
1
|
$self->{jss} = $jss; |
40
|
1
|
|
|
|
|
3
|
return $self; |
41
|
|
|
|
|
|
|
} ## end sub new |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
=head2 set_status($numerator, $denominator) |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
Updates the status of the job (most likely, a long-running job) and sends |
46
|
|
|
|
|
|
|
it back to the job server. I<$numerator> and I<$denominator> should |
47
|
|
|
|
|
|
|
represent the percentage completion of the job. |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
=cut |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
sub set_status { |
52
|
1
|
|
|
1
|
1
|
363
|
my $self = shift; |
53
|
1
|
|
|
|
|
2
|
my ($nu, $de) = @_; |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
my $req = Gearman::Util::pack_req_command("work_status", |
56
|
1
|
|
|
|
|
4
|
join("\0", $self->{handle}, $nu, $de)); |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
Carp::croak "work_status write failed" |
59
|
1
|
0
|
|
|
|
5
|
unless Gearman::Util::send_req($self->{jss}, \$req); |
60
|
|
|
|
|
|
|
|
61
|
0
|
|
|
|
|
0
|
return 1; |
62
|
|
|
|
|
|
|
} ## end sub set_status |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
=head2 argref() |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
=cut |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
sub argref { |
69
|
1
|
|
|
1
|
1
|
1
|
my $self = shift; |
70
|
1
|
|
|
|
|
3
|
return $self->{argref}; |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
=head2 arg() |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
B the scalar argument that the client sent to the job server. |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
=cut |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
sub arg { |
80
|
1
|
|
|
1
|
1
|
15
|
my $self = shift; |
81
|
1
|
|
|
|
|
1
|
return ${ $self->{argref} }; |
|
1
|
|
|
|
|
2
|
|
82
|
|
|
|
|
|
|
} |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
=head2 handle() |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
B handle |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
=cut |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
sub handle { |
91
|
1
|
|
|
1
|
1
|
358
|
my $self = shift; |
92
|
1
|
|
|
|
|
4
|
return $self->{handle}; |
93
|
|
|
|
|
|
|
} |
94
|
|
|
|
|
|
|
|