| 1 | package Gearman::Server::Job; | ||||||||||||||||||||||||||||
| 2 | 3 | ▶ | use version (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 3 | 3 | $Gearman::Server::Job::VERSION = version->declare("1.140_001"); | |||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||
| 5 | 3 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 3 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | =head1 NAME | ||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | Gearman::Server::Job - job representation of L<Gearman::Server> | ||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | =head1 METHODS | ||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | =cut | ||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | 3 | ▶ | use Gearman::Server::Client; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 19 | 3 | ▶ | use Scalar::Util; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 20 | 3 | ▶ | use Sys::Hostname; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||
| 22 | 3 | ▶ | use fields ( | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 23 | 3 | 'func', | |||||||||||||||||||||||||||
| 24 | 'uniq', | ||||||||||||||||||||||||||||
| 25 | 'argref', | ||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||
| 27 | # arrayref of interested Clients | ||||||||||||||||||||||||||||
| 28 | 'listeners', | ||||||||||||||||||||||||||||
| 29 | 'worker', | ||||||||||||||||||||||||||||
| 30 | 'handle', | ||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | # [1, 100] | ||||||||||||||||||||||||||||
| 33 | 'status', | ||||||||||||||||||||||||||||
| 34 | 'require_listener', | ||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||
| 36 | # Gearman::Server that owns us | ||||||||||||||||||||||||||||
| 37 | 'server', | ||||||||||||||||||||||||||||
| 38 | 3 | ); | |||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||
| 40 | 0 | ▶ | sub new { | ||||||||||||||||||||||||||
|
Subroutine
new: not called CC=5 SCAR=34.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 41 | 0 | my Gearman::Server::Job $self = shift; | |||||||||||||||||||||||||||
| 42 | 0 | my ($server, $func, $uniq, $argref, $highpri) = @_; | |||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||
| 44 | 0 | ▶ | $self = fields::new($self) unless ref $self; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||
| 46 | # if they specified a uniq, see if we have a dup job running already | ||||||||||||||||||||||||||||
| 47 | # to merge with | ||||||||||||||||||||||||||||
| 48 | 0 | ▶ | if (length($uniq)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | # a unique value of "-" means "use my args as my unique key" | ||||||||||||||||||||||||||||
| 51 | 0 | ▶ | $uniq = $$argref if $uniq eq "-"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 52 | 0 | ▶ | if (my $job = $server->job_of_unique($func, $uniq)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||
| 54 | # found a match | ||||||||||||||||||||||||||||
| 55 | 0 | return $job; | |||||||||||||||||||||||||||
| 56 | } | ||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||
| 58 | # create a new key | ||||||||||||||||||||||||||||
| 59 | 0 | $server->set_unique_job($func, $uniq => $self); | |||||||||||||||||||||||||||
| 60 | } ## end if (length($uniq)) | ||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||
| 62 | 0 | $self->{'server'} = $server; | |||||||||||||||||||||||||||
| 63 | 0 | $self->{'func'} = $func; | |||||||||||||||||||||||||||
| 64 | 0 | $self->{'uniq'} = $uniq; | |||||||||||||||||||||||||||
| 65 | 0 | $self->{'argref'} = $argref; | |||||||||||||||||||||||||||
| 66 | 0 | $self->{'require_listener'} = 1; | |||||||||||||||||||||||||||
| 67 | 0 | $self->{'listeners'} = []; | |||||||||||||||||||||||||||
| 68 | 0 | $self->{'handle'} = $server->new_job_handle; | |||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||
| 70 | 0 | $server->enqueue_job($self, $highpri); | |||||||||||||||||||||||||||
| 71 | 0 | return $self; | |||||||||||||||||||||||||||
| 72 | } ## end sub new | ||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||
| 74 | =head2 add_listener($client) | ||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||
| 76 | =cut | ||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||
| 78 | 0 | ▶ | sub add_listener { | ||||||||||||||||||||||||||
|
Subroutine
add_listener: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 79 | 0 | my Gearman::Server::Job $self = shift; | |||||||||||||||||||||||||||
| 80 | 0 | my Gearman::Server::Client $li = shift; | |||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||
| 82 | 0 | push @{ $self->{listeners} }, $li; | |||||||||||||||||||||||||||
| 83 | 0 | Scalar::Util::weaken($self->{listeners}->[-1]); | |||||||||||||||||||||||||||
| 84 | } ## end sub add_listener | ||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||
| 86 | =head2 relay_to_listeners($msg) | ||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||
| 88 | =cut | ||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||
| 90 | 0 | ▶ | sub relay_to_listeners { | ||||||||||||||||||||||||||
|
Subroutine
relay_to_listeners: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||||||||
| 91 | 0 | my Gearman::Server::Job $self = shift; | |||||||||||||||||||||||||||
| 92 | 0 | foreach my Gearman::Server::Client $c (@{ $self->{listeners} }) { | |||||||||||||||||||||||||||
| 93 | 0 | ▶ | next if !$c || $c->{closed}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
not $c or $c->{"closed"}
MC/DC0%0/2
not $c or $c->{"closed"}
not $c
$c->{"closed"}
Truth table0%0/3
not(A) or B
A= not $cB= $c->{"closed"}
| |||||||||||||||||||||||||||||
| 94 | 0 | $c->write($_[0]); | |||||||||||||||||||||||||||
| 95 | } | ||||||||||||||||||||||||||||
| 96 | } ## end sub relay_to_listeners | ||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||
| 98 | =head2 relay_to_option_listeners($msg, [$option]) | ||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||
| 100 | =cut | ||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||
| 102 | 0 | ▶ | sub relay_to_option_listeners { | ||||||||||||||||||||||||||
|
Subroutine
relay_to_option_listeners: not called CC=5 SCAR=34.0
Pod
documented
| |||||||||||||||||||||||||||||
| 103 | 0 | my Gearman::Server::Job $self = shift; | |||||||||||||||||||||||||||
| 104 | 0 | my $option = $_[1]; | |||||||||||||||||||||||||||
| 105 | 0 | foreach my Gearman::Server::Client $c (@{ $self->{listeners} }) { | |||||||||||||||||||||||||||
| 106 | 0 | ▶ | next if !$c || $c->{closed}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
not $c or $c->{"closed"}
MC/DC0%0/2
not $c or $c->{"closed"}
not $c
$c->{"closed"}
Truth table0%0/3
not(A) or B
A= not $cB= $c->{"closed"}
| |||||||||||||||||||||||||||||
| 107 | 0 | ▶ | next unless $c->option($option); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 108 | 0 | $c->write($_[0]); | |||||||||||||||||||||||||||
| 109 | } | ||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||
| 111 | } ## end sub relay_to_option_listeners | ||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||
| 113 | =head2 clear_listeners() | ||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||
| 115 | =cut | ||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||
| 117 | 0 | ▶ | sub clear_listeners { | ||||||||||||||||||||||||||
|
Subroutine
clear_listeners: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 118 | 0 | my Gearman::Server::Job $self = shift; | |||||||||||||||||||||||||||
| 119 | 0 | $self->{listeners} = []; | |||||||||||||||||||||||||||
| 120 | } | ||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||
| 122 | =head2 listeners() | ||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||
| 124 | =cut | ||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||
| 126 | 0 | ▶ | sub listeners { | ||||||||||||||||||||||||||
|
Subroutine
listeners: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 127 | 0 | my Gearman::Server::Job $self = shift; | |||||||||||||||||||||||||||
| 128 | 0 | return @{ $self->{listeners} }; | |||||||||||||||||||||||||||
| 129 | } | ||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||
| 131 | =head2 uniq() | ||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||
| 133 | =cut | ||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||
| 135 | 0 | ▶ | sub uniq { | ||||||||||||||||||||||||||
|
Subroutine
uniq: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 136 | 0 | my Gearman::Server::Job $self = shift; | |||||||||||||||||||||||||||
| 137 | 0 | return $self->{uniq}; | |||||||||||||||||||||||||||
| 138 | } | ||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||
| 140 | =head2 note_finished($success) | ||||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||||
| 142 | =cut | ||||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||
| 144 | 0 | ▶ | sub note_finished { | ||||||||||||||||||||||||||
|
Subroutine
note_finished: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 145 | 0 | my Gearman::Server::Job $self = shift; | |||||||||||||||||||||||||||
| 146 | 0 | my $success = shift; | |||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||
| 148 | 0 | $self->{server}->note_job_finished($self); | |||||||||||||||||||||||||||
| 149 | } ## end sub note_finished | ||||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||
| 151 | =head2 worker() | ||||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||
| 153 | =cut | ||||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||
| 155 | # accessors: | ||||||||||||||||||||||||||||
| 156 | 0 | ▶ | sub worker { | ||||||||||||||||||||||||||
|
Subroutine
worker: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 157 | 0 | my Gearman::Server::Job $self = shift; | |||||||||||||||||||||||||||
| 158 | 0 | ▶ | return $self->{'worker'} unless @_; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 159 | 0 | return $self->{'worker'} = shift; | |||||||||||||||||||||||||||
| 160 | } | ||||||||||||||||||||||||||||
| 161 | |||||||||||||||||||||||||||||
| 162 | =head2 require_listener([$require]) | ||||||||||||||||||||||||||||
| 163 | |||||||||||||||||||||||||||||
| 164 | =cut | ||||||||||||||||||||||||||||
| 165 | |||||||||||||||||||||||||||||
| 166 | 0 | ▶ | sub require_listener { | ||||||||||||||||||||||||||
|
Subroutine
require_listener: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 167 | 0 | my Gearman::Server::Job $self = shift; | |||||||||||||||||||||||||||
| 168 | 0 | ▶ | return $self->{'require_listener'} unless @_; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 169 | 0 | return $self->{'require_listener'} = shift; | |||||||||||||||||||||||||||
| 170 | } | ||||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||
| 172 | =head2 status([numerator,denominator]) | ||||||||||||||||||||||||||||
| 173 | |||||||||||||||||||||||||||||
| 174 | =cut | ||||||||||||||||||||||||||||
| 175 | |||||||||||||||||||||||||||||
| 176 | # takes arrayref of [numerator,denominator] | ||||||||||||||||||||||||||||
| 177 | 0 | ▶ | sub status { | ||||||||||||||||||||||||||
|
Subroutine
status: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 178 | 0 | my Gearman::Server::Job $self = shift; | |||||||||||||||||||||||||||
| 179 | 0 | ▶ | return $self->{'status'} unless @_; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 180 | 0 | return $self->{'status'} = shift; | |||||||||||||||||||||||||||
| 181 | } | ||||||||||||||||||||||||||||
| 182 | |||||||||||||||||||||||||||||
| 183 | =head2 handle() | ||||||||||||||||||||||||||||
| 184 | |||||||||||||||||||||||||||||
| 185 | =cut | ||||||||||||||||||||||||||||
| 186 | |||||||||||||||||||||||||||||
| 187 | 0 | ▶ | sub handle { | ||||||||||||||||||||||||||
|
Subroutine
handle: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 188 | 0 | my Gearman::Server::Job $self = shift; | |||||||||||||||||||||||||||
| 189 | 0 | return $self->{'handle'}; | |||||||||||||||||||||||||||
| 190 | } | ||||||||||||||||||||||||||||
| 191 | |||||||||||||||||||||||||||||
| 192 | =head2 func() | ||||||||||||||||||||||||||||
| 193 | |||||||||||||||||||||||||||||
| 194 | =cut | ||||||||||||||||||||||||||||
| 195 | |||||||||||||||||||||||||||||
| 196 | 0 | ▶ | sub func { | ||||||||||||||||||||||||||
|
Subroutine
func: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 197 | 0 | my Gearman::Server::Job $self = shift; | |||||||||||||||||||||||||||
| 198 | 0 | return $self->{'func'}; | |||||||||||||||||||||||||||
| 199 | } | ||||||||||||||||||||||||||||
| 200 | |||||||||||||||||||||||||||||
| 201 | =head2 argref() | ||||||||||||||||||||||||||||
| 202 | |||||||||||||||||||||||||||||
| 203 | =cut | ||||||||||||||||||||||||||||
| 204 | |||||||||||||||||||||||||||||
| 205 | 0 | ▶ | sub argref { | ||||||||||||||||||||||||||
|
Subroutine
argref: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 206 | 0 | my Gearman::Server::Job $self = shift; | |||||||||||||||||||||||||||
| 207 | 0 | return $self->{'argref'}; | |||||||||||||||||||||||||||
| 208 | } | ||||||||||||||||||||||||||||
| 209 | |||||||||||||||||||||||||||||
| 210 | 3 | 1; | |||||||||||||||||||||||||||