line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Gearman::Server::Job; |
2
|
1
|
|
|
1
|
|
3
|
use version; |
|
1
|
|
|
|
|
0
|
|
|
1
|
|
|
|
|
14
|
|
3
|
|
|
|
|
|
|
$Gearman::Server::Job::VERSION = qv("v1.130.1"); |
4
|
|
|
|
|
|
|
|
5
|
1
|
|
|
1
|
|
52
|
use strict; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
14
|
|
6
|
1
|
|
|
1
|
|
2
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
16
|
|
7
|
|
|
|
|
|
|
|
8
|
1
|
|
|
1
|
|
3
|
use Gearman::Server::Client; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
11
|
|
9
|
1
|
|
|
1
|
|
3
|
use Scalar::Util; |
|
1
|
|
|
|
|
0
|
|
|
1
|
|
|
|
|
39
|
|
10
|
1
|
|
|
1
|
|
368
|
use Sys::Hostname; |
|
1
|
|
|
|
|
698
|
|
|
1
|
|
|
|
|
51
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
use fields ( |
13
|
1
|
|
|
|
|
5
|
'func', |
14
|
|
|
|
|
|
|
'uniq', |
15
|
|
|
|
|
|
|
'argref', |
16
|
|
|
|
|
|
|
'listeners', # arrayref of interested Clients |
17
|
|
|
|
|
|
|
'worker', |
18
|
|
|
|
|
|
|
'handle', |
19
|
|
|
|
|
|
|
'status', # [1, 100] |
20
|
|
|
|
|
|
|
'require_listener', |
21
|
|
|
|
|
|
|
'server', # Gearman::Server that owns us |
22
|
1
|
|
|
1
|
|
3
|
); |
|
1
|
|
|
|
|
1
|
|
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
sub new { |
25
|
0
|
|
|
0
|
0
|
|
my Gearman::Server::Job $self = shift; |
26
|
0
|
|
|
|
|
|
my ($server, $func, $uniq, $argref, $highpri) = @_; |
27
|
|
|
|
|
|
|
|
28
|
0
|
0
|
|
|
|
|
$self = fields::new($self) unless ref $self; |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
# if they specified a uniq, see if we have a dup job running already |
31
|
|
|
|
|
|
|
# to merge with |
32
|
0
|
0
|
|
|
|
|
if (length($uniq)) { |
33
|
|
|
|
|
|
|
# a unique value of "-" means "use my args as my unique key" |
34
|
0
|
0
|
|
|
|
|
$uniq = $$argref if $uniq eq "-"; |
35
|
0
|
0
|
|
|
|
|
if (my $job = $server->job_of_unique($func, $uniq)) { |
36
|
|
|
|
|
|
|
# found a match |
37
|
0
|
|
|
|
|
|
return $job; |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
# create a new key |
40
|
0
|
|
|
|
|
|
$server->set_unique_job($func, $uniq => $self); |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
|
43
|
0
|
|
|
|
|
|
$self->{'server'} = $server; |
44
|
0
|
|
|
|
|
|
$self->{'func'} = $func; |
45
|
0
|
|
|
|
|
|
$self->{'uniq'} = $uniq; |
46
|
0
|
|
|
|
|
|
$self->{'argref'} = $argref; |
47
|
0
|
|
|
|
|
|
$self->{'require_listener'} = 1; |
48
|
0
|
|
|
|
|
|
$self->{'listeners'} = []; |
49
|
0
|
|
|
|
|
|
$self->{'handle'} = $server->new_job_handle; |
50
|
|
|
|
|
|
|
|
51
|
0
|
|
|
|
|
|
$server->enqueue_job($self, $highpri); |
52
|
0
|
|
|
|
|
|
return $self; |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
sub add_listener { |
56
|
0
|
|
|
0
|
0
|
|
my Gearman::Server::Job $self = shift; |
57
|
0
|
|
|
|
|
|
my Gearman::Server::Client $li = shift; |
58
|
|
|
|
|
|
|
|
59
|
0
|
|
|
|
|
|
push @{$self->{listeners}}, $li; |
|
0
|
|
|
|
|
|
|
60
|
0
|
|
|
|
|
|
Scalar::Util::weaken($self->{listeners}->[-1]); |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
sub relay_to_listeners { |
64
|
0
|
|
|
0
|
0
|
|
my Gearman::Server::Job $self = shift; |
65
|
0
|
|
|
|
|
|
foreach my Gearman::Server::Client $c (@{$self->{listeners}}) { |
|
0
|
|
|
|
|
|
|
66
|
0
|
0
|
0
|
|
|
|
next if !$c || $c->{closed}; |
67
|
0
|
|
|
|
|
|
$c->write($_[0]); |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
sub relay_to_option_listeners { |
72
|
0
|
|
|
0
|
0
|
|
my Gearman::Server::Job $self = shift; |
73
|
0
|
|
|
|
|
|
my $option = $_[1]; |
74
|
0
|
|
|
|
|
|
foreach my Gearman::Server::Client $c (@{$self->{listeners}}) { |
|
0
|
|
|
|
|
|
|
75
|
0
|
0
|
0
|
|
|
|
next if !$c || $c->{closed}; |
76
|
0
|
0
|
|
|
|
|
next unless $c->option($option); |
77
|
0
|
|
|
|
|
|
$c->write($_[0]); |
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
sub clear_listeners { |
83
|
0
|
|
|
0
|
0
|
|
my Gearman::Server::Job $self = shift; |
84
|
0
|
|
|
|
|
|
$self->{listeners} = []; |
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
sub listeners { |
88
|
0
|
|
|
0
|
0
|
|
my Gearman::Server::Job $self = shift; |
89
|
0
|
|
|
|
|
|
return @{$self->{listeners}}; |
|
0
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
} |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
sub uniq { |
93
|
0
|
|
|
0
|
0
|
|
my Gearman::Server::Job $self = shift; |
94
|
0
|
|
|
|
|
|
return $self->{uniq}; |
95
|
|
|
|
|
|
|
} |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
sub note_finished { |
98
|
0
|
|
|
0
|
0
|
|
my Gearman::Server::Job $self = shift; |
99
|
0
|
|
|
|
|
|
my $success = shift; |
100
|
|
|
|
|
|
|
|
101
|
0
|
|
|
|
|
|
$self->{server}->note_job_finished($self); |
102
|
|
|
|
|
|
|
|
103
|
0
|
0
|
|
|
|
|
if ($Gearmand::graceful_shutdown) { |
104
|
0
|
|
|
|
|
|
Gearmand::shutdown_if_calm(); |
105
|
|
|
|
|
|
|
} |
106
|
|
|
|
|
|
|
} |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
# accessors: |
109
|
|
|
|
|
|
|
sub worker { |
110
|
0
|
|
|
0
|
0
|
|
my Gearman::Server::Job $self = shift; |
111
|
0
|
0
|
|
|
|
|
return $self->{'worker'} unless @_; |
112
|
0
|
|
|
|
|
|
return $self->{'worker'} = shift; |
113
|
|
|
|
|
|
|
} |
114
|
|
|
|
|
|
|
sub require_listener { |
115
|
0
|
|
|
0
|
0
|
|
my Gearman::Server::Job $self = shift; |
116
|
0
|
0
|
|
|
|
|
return $self->{'require_listener'} unless @_; |
117
|
0
|
|
|
|
|
|
return $self->{'require_listener'} = shift; |
118
|
|
|
|
|
|
|
} |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
# takes arrayref of [numerator,denominator] |
121
|
|
|
|
|
|
|
sub status { |
122
|
0
|
|
|
0
|
0
|
|
my Gearman::Server::Job $self = shift; |
123
|
0
|
0
|
|
|
|
|
return $self->{'status'} unless @_; |
124
|
0
|
|
|
|
|
|
return $self->{'status'} = shift; |
125
|
|
|
|
|
|
|
} |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
sub handle { |
128
|
0
|
|
|
0
|
0
|
|
my Gearman::Server::Job $self = shift; |
129
|
0
|
|
|
|
|
|
return $self->{'handle'}; |
130
|
|
|
|
|
|
|
} |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
sub func { |
133
|
0
|
|
|
0
|
0
|
|
my Gearman::Server::Job $self = shift; |
134
|
0
|
|
|
|
|
|
return $self->{'func'}; |
135
|
|
|
|
|
|
|
} |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
sub argref { |
138
|
0
|
|
|
0
|
0
|
|
my Gearman::Server::Job $self = shift; |
139
|
0
|
|
|
|
|
|
return $self->{'argref'}; |
140
|
|
|
|
|
|
|
} |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
1; |