| 1 | package Gearman::Task; | ||||||||||||||||||||||||||||||||
| 2 | 7 | ▶ | use version; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 3 | 7 | $Gearman::Task::VERSION = version->declare("2.003_001"); | |||||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||||||
| 5 | 7 | ▶ | use strict; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 6 | 7 | ▶ | use warnings; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||
| 8 | =head1 NAME | ||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||
| 10 | Gearman::Task - a task in Gearman, from the point of view of a client | ||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||
| 12 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||
| 14 | my $task = Gearman::Task->new("add", "1+2", { | ||||||||||||||||||||||||||||||||
| 15 | ... | ||||||||||||||||||||||||||||||||
| 16 | }); | ||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||
| 18 | $taskset->add_task($task); | ||||||||||||||||||||||||||||||||
| 19 | $client->do_task($task); | ||||||||||||||||||||||||||||||||
| 20 | $client->dispatch_background($task); | ||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||
| 23 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||
| 25 | I<Gearman::Task> is a Gearman::Client's representation of a task to be | ||||||||||||||||||||||||||||||||
| 26 | done. | ||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||
| 28 | =head1 USAGE | ||||||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||||||
| 30 | =head2 Gearman::Task->new($func, $arg, \%options) | ||||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||||
| 32 | Creates a new I<Gearman::Task> object, and returns the object. | ||||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||||
| 34 | I<$func> is the function name to be run. (that you have a worker registered to process) | ||||||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||||||
| 36 | I<$arg> is an opaque scalar or scalarref representing the argument(s) | ||||||||||||||||||||||||||||||||
| 37 | to pass to the distributed function. If you want to pass multiple | ||||||||||||||||||||||||||||||||
| 38 | arguments, you must encode them somehow into this one. That's up to | ||||||||||||||||||||||||||||||||
| 39 | you and your worker. | ||||||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||||||
| 41 | I<%options> can contain: | ||||||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||||||
| 43 | =over 4 | ||||||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||||||
| 45 | =item * uniq | ||||||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||||||
| 47 | A key which indicates to the server that other tasks with the same | ||||||||||||||||||||||||||||||||
| 48 | function name and key will be merged into one. That is, the task | ||||||||||||||||||||||||||||||||
| 49 | will be run just once, but all the listeners waiting on that job | ||||||||||||||||||||||||||||||||
| 50 | will get the response multiplexed back to them. | ||||||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||||||
| 52 | Uniq may also contain the magic value "-" (a single hyphen) which | ||||||||||||||||||||||||||||||||
| 53 | means the uniq key is the contents of the args. | ||||||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||||||
| 55 | =item * on_complete | ||||||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||||||
| 57 | A subroutine reference to be invoked when the task is completed. The | ||||||||||||||||||||||||||||||||
| 58 | subroutine will be passed a reference to the return value from the worker | ||||||||||||||||||||||||||||||||
| 59 | process. | ||||||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||||||
| 61 | =item * on_fail | ||||||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||||||
| 63 | A subroutine reference to be invoked when the task fails (or fails for | ||||||||||||||||||||||||||||||||
| 64 | the last time, if retries were specified). The reason could be passed | ||||||||||||||||||||||||||||||||
| 65 | to this callback as an argument. This callback won't be called after a | ||||||||||||||||||||||||||||||||
| 66 | failure if more retries are still possible. | ||||||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||||||
| 68 | =item * on_retry | ||||||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||||||
| 70 | A subroutine reference to be invoked when the task fails, but is about | ||||||||||||||||||||||||||||||||
| 71 | to be retried. | ||||||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||||||
| 73 | Is passed one argument, what retry attempt number this is. (starts with 1) | ||||||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||||||
| 75 | =item * on_status | ||||||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||||||
| 77 | A subroutine reference to be invoked if the task emits status updates. | ||||||||||||||||||||||||||||||||
| 78 | Arguments passed to the subref are ($numerator, $denominator), where those | ||||||||||||||||||||||||||||||||
| 79 | are left up to the client and job to determine. | ||||||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||||||
| 81 | =item * on_warning | ||||||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||||||
| 83 | A subroutine reference to be invoked if the task emits status updates. | ||||||||||||||||||||||||||||||||
| 84 | Arguments passed to the subref are ($numerator, $denominator), where those | ||||||||||||||||||||||||||||||||
| 85 | are left up to the client and job to determine. | ||||||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||||||
| 87 | =item * retry_count | ||||||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||||||
| 89 | Number of times job will be retried if there are failures. Defaults to 0. | ||||||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||||||
| 91 | =item * high_priority | ||||||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||||||
| 93 | B<the option high_priority is deprecated>. Use C<< priority => high >> instead. | ||||||||||||||||||||||||||||||||
| 94 | Boolean, whether this job should take priority over other jobs already | ||||||||||||||||||||||||||||||||
| 95 | enqueued. | ||||||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||||||
| 97 | =item * priority | ||||||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||||||
| 99 | valid value: | ||||||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||||||
| 101 | =over | ||||||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||||||
| 103 | =item | ||||||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||||||
| 105 | high | ||||||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||||||
| 107 | =item | ||||||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||||||
| 109 | normal (defaul) | ||||||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||||||
| 111 | =item | ||||||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||||||
| 113 | low | ||||||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||||||
| 115 | =back | ||||||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||||||
| 117 | =item * timeout | ||||||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||||||
| 119 | Automatically fail, calling your on_fail callback, after this many | ||||||||||||||||||||||||||||||||
| 120 | seconds have elapsed without an on_fail or on_complete being | ||||||||||||||||||||||||||||||||
| 121 | called. Defaults to 0, which means never. Bypasses any retry_count | ||||||||||||||||||||||||||||||||
| 122 | remaining. | ||||||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||||||
| 124 | =item * try_timeout | ||||||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||||||
| 126 | Automatically fail, calling your on_retry callback (or on_fail if out of | ||||||||||||||||||||||||||||||||
| 127 | retries), after this many seconds have elapsed. Defaults to 0, which means | ||||||||||||||||||||||||||||||||
| 128 | never. | ||||||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||||||
| 130 | =back | ||||||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||||||
| 132 | =head1 METHODS | ||||||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||||||
| 134 | =cut | ||||||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||||||
| 136 | 7 | ▶ | use Carp (); | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 137 | 7 | ▶ | use Gearman::Util (); | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 138 | 7 | ▶ | use Scalar::Util (); | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 139 | 7 | ▶ | use String::CRC32 (); | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 140 | 7 | ▶ | use Storable (); | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||||||||
| 142 | use fields ( | ||||||||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||||||
| 144 | # from client: | ||||||||||||||||||||||||||||||||
| 145 | 7 | 'func', | |||||||||||||||||||||||||||||||
| 146 | 'argref', | ||||||||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||||||
| 148 | # opts from client: | ||||||||||||||||||||||||||||||||
| 149 | 'uniq', | ||||||||||||||||||||||||||||||||
| 150 | 'on_complete', | ||||||||||||||||||||||||||||||||
| 151 | 'on_data', | ||||||||||||||||||||||||||||||||
| 152 | 'on_fail', | ||||||||||||||||||||||||||||||||
| 153 | 'on_exception', | ||||||||||||||||||||||||||||||||
| 154 | 'on_warning', | ||||||||||||||||||||||||||||||||
| 155 | 'on_retry', | ||||||||||||||||||||||||||||||||
| 156 | 'on_status', | ||||||||||||||||||||||||||||||||
| 157 | 'on_post_hooks', | ||||||||||||||||||||||||||||||||
| 158 | |||||||||||||||||||||||||||||||||
| 159 | # used internally, | ||||||||||||||||||||||||||||||||
| 160 | # when other hooks are done running, | ||||||||||||||||||||||||||||||||
| 161 | # prior to cleanup | ||||||||||||||||||||||||||||||||
| 162 | 'retry_count', | ||||||||||||||||||||||||||||||||
| 163 | 'timeout', | ||||||||||||||||||||||||||||||||
| 164 | 'try_timeout', | ||||||||||||||||||||||||||||||||
| 165 | 'high_priority', | ||||||||||||||||||||||||||||||||
| 166 | 'background', | ||||||||||||||||||||||||||||||||
| 167 | |||||||||||||||||||||||||||||||||
| 168 | # from server: | ||||||||||||||||||||||||||||||||
| 169 | 'handle', | ||||||||||||||||||||||||||||||||
| 170 | |||||||||||||||||||||||||||||||||
| 171 | # maintained by this module: | ||||||||||||||||||||||||||||||||
| 172 | 'retries_done', | ||||||||||||||||||||||||||||||||
| 173 | 'is_finished', | ||||||||||||||||||||||||||||||||
| 174 | 'taskset', | ||||||||||||||||||||||||||||||||
| 175 | |||||||||||||||||||||||||||||||||
| 176 | # jobserver socket. | ||||||||||||||||||||||||||||||||
| 177 | # shared by other tasks in the same taskset, | ||||||||||||||||||||||||||||||||
| 178 | # but not w/ tasks in other tasksets using | ||||||||||||||||||||||||||||||||
| 179 | # the same Gearman::Client | ||||||||||||||||||||||||||||||||
| 180 | 'jssock', | ||||||||||||||||||||||||||||||||
| 181 | |||||||||||||||||||||||||||||||||
| 182 | # hookname -> coderef | ||||||||||||||||||||||||||||||||
| 183 | 'hooks', | ||||||||||||||||||||||||||||||||
| 184 | 'priority', | ||||||||||||||||||||||||||||||||
| 185 | 7 | ▶ | ); | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 186 | |||||||||||||||||||||||||||||||||
| 187 | # constructor, given: ($func, $argref, $opts); | ||||||||||||||||||||||||||||||||
| 188 | sub new { | ||||||||||||||||||||||||||||||||
| 189 | 17 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=9 SCAR=22.1
Pod
documented
| |||||||||||||||||||||||||||||||||
| 190 | 17 | ▶ | unless (ref $self) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 191 | 17 | $self = fields::new($self); | |||||||||||||||||||||||||||||||
| 192 | } | ||||||||||||||||||||||||||||||||
| 193 | |||||||||||||||||||||||||||||||||
| 194 | $self->{func} = shift | ||||||||||||||||||||||||||||||||
| 195 | 17 | ▶ | or Carp::croak("No function given"); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 196 | |||||||||||||||||||||||||||||||||
| 197 | 17 | ▶ | $self->{argref} = shift || do { my $empty = ""; \$empty; }; | ||||||||||||||||||||||||||||||
|
Condition66%2/3
shift() || do {
my $empty = '';
\$empty
}
MC/DC0%0/2
shift() || do {
my $empty = '';
\$empty
}
shift()
do {
my $empty = '';
\$empty
}
Truth table66%2/3
A || B
A= shift()B= do {
my $empty = '';
\$empty
}
| |||||||||||||||||||||||||||||||||
| 198 | 17 | ▶ | (ref $self->{argref} eq "SCALAR") | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 199 | || Carp::croak("Argref not a scalar reference"); | ||||||||||||||||||||||||||||||||
| 200 | |||||||||||||||||||||||||||||||||
| 201 | 17 | ▶ | my $opts = shift || {}; | ||||||||||||||||||||||||||||||
|
Condition100%2/2
shift() || {}
MC/DC100%1/1
shift() || {}
shift()
Truth table100%2/2
A
A= shift()
| |||||||||||||||||||||||||||||||||
| 202 | |||||||||||||||||||||||||||||||||
| 203 | 17 | $self->{$_} = delete $opts->{$_} for qw/ | |||||||||||||||||||||||||||||||
| 204 | background | ||||||||||||||||||||||||||||||||
| 205 | high_priority | ||||||||||||||||||||||||||||||||
| 206 | on_complete | ||||||||||||||||||||||||||||||||
| 207 | on_data | ||||||||||||||||||||||||||||||||
| 208 | on_exception | ||||||||||||||||||||||||||||||||
| 209 | on_fail | ||||||||||||||||||||||||||||||||
| 210 | on_retry | ||||||||||||||||||||||||||||||||
| 211 | on_status | ||||||||||||||||||||||||||||||||
| 212 | on_warning | ||||||||||||||||||||||||||||||||
| 213 | retry_count | ||||||||||||||||||||||||||||||||
| 214 | timeout | ||||||||||||||||||||||||||||||||
| 215 | try_timeout | ||||||||||||||||||||||||||||||||
| 216 | uniq | ||||||||||||||||||||||||||||||||
| 217 | /; | ||||||||||||||||||||||||||||||||
| 218 | |||||||||||||||||||||||||||||||||
| 219 | 17 | $self->_priority(delete $opts->{priority}); | |||||||||||||||||||||||||||||||
| 220 | |||||||||||||||||||||||||||||||||
| 221 | 17 | ▶ | $self->{retry_count} ||= 0; | ||||||||||||||||||||||||||||||
|
Condition100%2/2
$self->{"retry_count"} ||= 0
MC/DC100%1/1
$self->{"retry_count"} ||= 0
$self->{"retry_count"}
Truth table100%2/2
A
A= $self->{"retry_count"}
| |||||||||||||||||||||||||||||||||
| 222 | |||||||||||||||||||||||||||||||||
| 223 | # bool: if success or fail has been called yet on this. | ||||||||||||||||||||||||||||||||
| 224 | 17 | $self->{is_finished} = 0; | |||||||||||||||||||||||||||||||
| 225 | |||||||||||||||||||||||||||||||||
| 226 | 17 | ▶ | if (%{$opts}) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 227 | 1 | Carp::croak("Unknown option(s): " . join(", ", sort keys %$opts)); | |||||||||||||||||||||||||||||||
| 228 | } | ||||||||||||||||||||||||||||||||
| 229 | |||||||||||||||||||||||||||||||||
| 230 | 16 | $self->{retries_done} = 0; | |||||||||||||||||||||||||||||||
| 231 | |||||||||||||||||||||||||||||||||
| 232 | 16 | return $self; | |||||||||||||||||||||||||||||||
| 233 | } ## end sub new | ||||||||||||||||||||||||||||||||
| 234 | |||||||||||||||||||||||||||||||||
| 235 | =head2 run_hook($name) | ||||||||||||||||||||||||||||||||
| 236 | |||||||||||||||||||||||||||||||||
| 237 | run a hook callback if defined | ||||||||||||||||||||||||||||||||
| 238 | |||||||||||||||||||||||||||||||||
| 239 | =cut | ||||||||||||||||||||||||||||||||
| 240 | |||||||||||||||||||||||||||||||||
| 241 | sub run_hook { | ||||||||||||||||||||||||||||||||
| 242 | 7 | ▶ | my ($self, $name) = (shift, shift); | ||||||||||||||||||||||||||||||
|
Subroutine
run_hook: called CC=4 SCAR=14.0
Pod
documented
| |||||||||||||||||||||||||||||||||
| 243 | 7 | ▶ | ($name && $self->{hooks}->{$name}) || return; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$name and $self->{"hooks"}{$name}
MC/DC50%1/2
$name and $self->{"hooks"}{$name}
$name
$self->{"hooks"}{$name}
Truth table66%2/3
A and B
A= $nameB= $self->{"hooks"}{$name}
| |||||||||||||||||||||||||||||||||
| 244 | |||||||||||||||||||||||||||||||||
| 245 | 1 | eval { $self->{hooks}->{$name}->(@_) }; | |||||||||||||||||||||||||||||||
| 246 | 1 | ▶ | warn "Gearman::Task hook '$name' threw error: $@\n" if $@; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 247 | } ## end sub run_hook | ||||||||||||||||||||||||||||||||
| 248 | |||||||||||||||||||||||||||||||||
| 249 | =head2 add_hook($name, $cb) | ||||||||||||||||||||||||||||||||
| 250 | |||||||||||||||||||||||||||||||||
| 251 | add a hook | ||||||||||||||||||||||||||||||||
| 252 | |||||||||||||||||||||||||||||||||
| 253 | =cut | ||||||||||||||||||||||||||||||||
| 254 | |||||||||||||||||||||||||||||||||
| 255 | sub add_hook { | ||||||||||||||||||||||||||||||||
| 256 | 2 | ▶ | my ($self, $name) = (shift, shift); | ||||||||||||||||||||||||||||||
|
Subroutine
add_hook: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||
| 257 | 2 | ▶ | $name || return; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 258 | |||||||||||||||||||||||||||||||||
| 259 | 2 | ▶ | if (@_) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 260 | 1 | $self->{hooks}->{$name} = shift; | |||||||||||||||||||||||||||||||
| 261 | } | ||||||||||||||||||||||||||||||||
| 262 | else { | ||||||||||||||||||||||||||||||||
| 263 | 1 | delete $self->{hooks}->{$name}; | |||||||||||||||||||||||||||||||
| 264 | } | ||||||||||||||||||||||||||||||||
| 265 | } ## end sub add_hook | ||||||||||||||||||||||||||||||||
| 266 | |||||||||||||||||||||||||||||||||
| 267 | =head2 is_finished() | ||||||||||||||||||||||||||||||||
| 268 | |||||||||||||||||||||||||||||||||
| 269 | |||||||||||||||||||||||||||||||||
| 270 | B<return> bool: whether or not task is totally done (on_failure or | ||||||||||||||||||||||||||||||||
| 271 | on_complete callback has been called) | ||||||||||||||||||||||||||||||||
| 272 | |||||||||||||||||||||||||||||||||
| 273 | =cut | ||||||||||||||||||||||||||||||||
| 274 | |||||||||||||||||||||||||||||||||
| 275 | sub is_finished { | ||||||||||||||||||||||||||||||||
| 276 | 0 | ▶ | return shift->{is_finished}; | ||||||||||||||||||||||||||||||
|
Subroutine
is_finished: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||
| 277 | } | ||||||||||||||||||||||||||||||||
| 278 | |||||||||||||||||||||||||||||||||
| 279 | =head2 taskset() | ||||||||||||||||||||||||||||||||
| 280 | |||||||||||||||||||||||||||||||||
| 281 | getter | ||||||||||||||||||||||||||||||||
| 282 | |||||||||||||||||||||||||||||||||
| 283 | =head2 taskset($ts) | ||||||||||||||||||||||||||||||||
| 284 | |||||||||||||||||||||||||||||||||
| 285 | setter | ||||||||||||||||||||||||||||||||
| 286 | |||||||||||||||||||||||||||||||||
| 287 | B<return> Gearman::Taskset | ||||||||||||||||||||||||||||||||
| 288 | |||||||||||||||||||||||||||||||||
| 289 | =cut | ||||||||||||||||||||||||||||||||
| 290 | |||||||||||||||||||||||||||||||||
| 291 | sub taskset { | ||||||||||||||||||||||||||||||||
| 292 | 6 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||
|
Subroutine
taskset: called CC=5 SCAR=16.3
Pod
documented
| |||||||||||||||||||||||||||||||||
| 293 | |||||||||||||||||||||||||||||||||
| 294 | # getter | ||||||||||||||||||||||||||||||||
| 295 | 6 | ▶ | return $self->{taskset} unless @_; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 296 | |||||||||||||||||||||||||||||||||
| 297 | # setter | ||||||||||||||||||||||||||||||||
| 298 | 3 | my $ts = shift; | |||||||||||||||||||||||||||||||
| 299 | 3 | ▶ | (Scalar::Util::blessed($ts) && $ts->isa("Gearman::Taskset")) | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
builtin::blessed($ts) and $ts->isa("Gearman::Taskset")
MC/DC50%1/2
builtin::blessed($ts) and $ts->isa("Gearman::Taskset")
builtin::blessed($ts)
$ts->isa("Gearman::Taskset")
Truth table66%2/3
A and B
A= builtin::blessed($ts)B= $ts->isa("Gearman::Taskset")
| |||||||||||||||||||||||||||||||||
| 300 | || Carp::croak("argument is not an instance of Gearman::Taskset"); | ||||||||||||||||||||||||||||||||
| 301 | 2 | $self->{taskset} = $ts; | |||||||||||||||||||||||||||||||
| 302 | |||||||||||||||||||||||||||||||||
| 303 | 2 | ▶ | if (my $hash_num = $self->hash()) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 304 | 2 | $self->{jssock} = $ts->_get_hashed_sock($hash_num); | |||||||||||||||||||||||||||||||
| 305 | } | ||||||||||||||||||||||||||||||||
| 306 | else { | ||||||||||||||||||||||||||||||||
| 307 | 0 | $self->{jssock} = $ts->_get_default_sock; | |||||||||||||||||||||||||||||||
| 308 | } | ||||||||||||||||||||||||||||||||
| 309 | |||||||||||||||||||||||||||||||||
| 310 | 2 | return $self->{taskset}; | |||||||||||||||||||||||||||||||
| 311 | } ## end sub taskset | ||||||||||||||||||||||||||||||||
| 312 | |||||||||||||||||||||||||||||||||
| 313 | =head2 hash() | ||||||||||||||||||||||||||||||||
| 314 | |||||||||||||||||||||||||||||||||
| 315 | B<return> undef on non-uniq packet, or the hash value (0-32767) if uniq | ||||||||||||||||||||||||||||||||
| 316 | |||||||||||||||||||||||||||||||||
| 317 | =cut | ||||||||||||||||||||||||||||||||
| 318 | |||||||||||||||||||||||||||||||||
| 319 | sub hash { | ||||||||||||||||||||||||||||||||
| 320 | 6 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||
|
Subroutine
hash: called CC=4 SCAR=14.2
Pod
documented
| |||||||||||||||||||||||||||||||||
| 321 | my $merge_on = $self->{uniq} | ||||||||||||||||||||||||||||||||
| 322 | 6 | ▶ | && $self->{uniq} eq "-" ? $self->{argref} : \$self->{uniq}; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$self->{"uniq"} and $self->{"uniq"} eq "-"
MC/DC50%1/2
$self->{"uniq"} and $self->{"uniq"} eq "-"
$self->{"uniq"}
$self->{"uniq"} eq "-"
Truth table66%2/3
A and B
A= $self->{"uniq"}B= $self->{"uniq"} eq "-"
| |||||||||||||||||||||||||||||||||
| 323 | 6 | ▶ | if (${$merge_on}) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 324 | 6 | return (String::CRC32::crc32(${$merge_on}) >> 16) & 0x7fff; | |||||||||||||||||||||||||||||||
| 325 | } | ||||||||||||||||||||||||||||||||
| 326 | else { | ||||||||||||||||||||||||||||||||
| 327 | 0 | return; | |||||||||||||||||||||||||||||||
| 328 | } | ||||||||||||||||||||||||||||||||
| 329 | } ## end sub hash | ||||||||||||||||||||||||||||||||
| 330 | |||||||||||||||||||||||||||||||||
| 331 | =head2 pack_submit_packet($client) | ||||||||||||||||||||||||||||||||
| 332 | |||||||||||||||||||||||||||||||||
| 333 | B<return> Gearman::Util::pack_req_command(mode, func, uniq, argref) | ||||||||||||||||||||||||||||||||
| 334 | |||||||||||||||||||||||||||||||||
| 335 | =cut | ||||||||||||||||||||||||||||||||
| 336 | |||||||||||||||||||||||||||||||||
| 337 | sub pack_submit_packet { | ||||||||||||||||||||||||||||||||
| 338 | 0 | ▶ | my ($self, $client) = @_; | ||||||||||||||||||||||||||||||
|
Subroutine
pack_submit_packet: not called CC=5 SCAR=34.0
Pod
documented
| |||||||||||||||||||||||||||||||||
| 339 | 0 | ▶ | ref($client) or Carp::croak("client parameter missed"); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 340 | 0 | my $func = $client->func($self->{func}); | |||||||||||||||||||||||||||||||
| 341 | |||||||||||||||||||||||||||||||||
| 342 | return Gearman::Util::pack_req_command( | ||||||||||||||||||||||||||||||||
| 343 | $self->mode, | ||||||||||||||||||||||||||||||||
| 344 | join( | ||||||||||||||||||||||||||||||||
| 345 | 0 | ▶ | "\0", $func || '', $self->{uniq} || '', ${ $self->{argref} } || '' | ||||||||||||||||||||||||||||||
|
Condition0%0/6
$func || ''
$self->{'uniq'} || ''
${$self->{'argref'};} || ''
MC/DC0%0/1
$func || ''
$func
MC/DC0%0/1
$self->{'uniq'} || ''
$self->{'uniq'}
MC/DC0%0/1
${$self->{'argref'};} || ''
${$self->{'argref'};}
Truth table0%0/2
A
A= $func
Truth table0%0/2
A
A= $self->{'uniq'}
Truth table0%0/2
A
A= ${$self->{'argref'};}
| |||||||||||||||||||||||||||||||||
| 346 | ) | ||||||||||||||||||||||||||||||||
| 347 | ); | ||||||||||||||||||||||||||||||||
| 348 | } ## end sub pack_submit_packet | ||||||||||||||||||||||||||||||||
| 349 | |||||||||||||||||||||||||||||||||
| 350 | =head2 fail($reason) | ||||||||||||||||||||||||||||||||
| 351 | |||||||||||||||||||||||||||||||||
| 352 | =cut | ||||||||||||||||||||||||||||||||
| 353 | |||||||||||||||||||||||||||||||||
| 354 | sub fail { | ||||||||||||||||||||||||||||||||
| 355 | 5 | ▶ | my ($self, $reason) = @_; | ||||||||||||||||||||||||||||||
|
Subroutine
fail: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||||||
| 356 | 5 | ▶ | return if $self->{is_finished}; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 357 | |||||||||||||||||||||||||||||||||
| 358 | # try to retry, if we can | ||||||||||||||||||||||||||||||||
| 359 | 4 | ▶ | if ($self->{retries_done} < $self->{retry_count}) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 360 | 1 | $self->{retries_done}++; | |||||||||||||||||||||||||||||||
| 361 | 1 | ▶ | $self->{on_retry}->($self->{retries_done}) if $self->{on_retry}; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 362 | 1 | $self->handle(undef); | |||||||||||||||||||||||||||||||
| 363 | 1 | return $self->{taskset}->add_task($self); | |||||||||||||||||||||||||||||||
| 364 | } ## end if ($self->{retries_done...}) | ||||||||||||||||||||||||||||||||
| 365 | |||||||||||||||||||||||||||||||||
| 366 | 3 | $self->final_fail($reason); | |||||||||||||||||||||||||||||||
| 367 | } ## end sub fail | ||||||||||||||||||||||||||||||||
| 368 | |||||||||||||||||||||||||||||||||
| 369 | =head2 final_fail($reason) | ||||||||||||||||||||||||||||||||
| 370 | |||||||||||||||||||||||||||||||||
| 371 | run if !is_finished | ||||||||||||||||||||||||||||||||
| 372 | |||||||||||||||||||||||||||||||||
| 373 | =over | ||||||||||||||||||||||||||||||||
| 374 | |||||||||||||||||||||||||||||||||
| 375 | =item | ||||||||||||||||||||||||||||||||
| 376 | |||||||||||||||||||||||||||||||||
| 377 | on_fail | ||||||||||||||||||||||||||||||||
| 378 | |||||||||||||||||||||||||||||||||
| 379 | =item | ||||||||||||||||||||||||||||||||
| 380 | |||||||||||||||||||||||||||||||||
| 381 | on_post_hooks | ||||||||||||||||||||||||||||||||
| 382 | |||||||||||||||||||||||||||||||||
| 383 | =back | ||||||||||||||||||||||||||||||||
| 384 | |||||||||||||||||||||||||||||||||
| 385 | =cut | ||||||||||||||||||||||||||||||||
| 386 | |||||||||||||||||||||||||||||||||
| 387 | sub final_fail { | ||||||||||||||||||||||||||||||||
| 388 | 4 | ▶ | my ($self, $reason) = @_; | ||||||||||||||||||||||||||||||
|
Subroutine
final_fail: called CC=5 SCAR=16.4
Pod
documented
| |||||||||||||||||||||||||||||||||
| 389 | |||||||||||||||||||||||||||||||||
| 390 | 4 | ▶ | return if $self->{is_finished}; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 391 | 4 | ▶ | $self->{is_finished} = $reason || 1; | ||||||||||||||||||||||||||||||
|
Condition50%1/2
$reason || 1
MC/DC0%0/1
$reason || 1
$reason
Truth table50%1/2
A
A= $reason
| |||||||||||||||||||||||||||||||||
| 392 | |||||||||||||||||||||||||||||||||
| 393 | 4 | $self->run_hook('final_fail', $self); | |||||||||||||||||||||||||||||||
| 394 | |||||||||||||||||||||||||||||||||
| 395 | 4 | ▶ | $self->{on_fail}->($reason) if $self->{on_fail}; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 396 | 4 | ▶ | $self->{on_post_hooks}->() if $self->{on_post_hooks}; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 397 | 4 | $self->wipe; | |||||||||||||||||||||||||||||||
| 398 | |||||||||||||||||||||||||||||||||
| 399 | 4 | return; | |||||||||||||||||||||||||||||||
| 400 | } ## end sub final_fail | ||||||||||||||||||||||||||||||||
| 401 | |||||||||||||||||||||||||||||||||
| 402 | #FIXME obsolete? | ||||||||||||||||||||||||||||||||
| 403 | |||||||||||||||||||||||||||||||||
| 404 | =head2 exception($exc_ref) | ||||||||||||||||||||||||||||||||
| 405 | |||||||||||||||||||||||||||||||||
| 406 | $exc_ref may be a Storable serialized value | ||||||||||||||||||||||||||||||||
| 407 | |||||||||||||||||||||||||||||||||
| 408 | run on_exception if defined | ||||||||||||||||||||||||||||||||
| 409 | |||||||||||||||||||||||||||||||||
| 410 | =cut | ||||||||||||||||||||||||||||||||
| 411 | |||||||||||||||||||||||||||||||||
| 412 | sub exception { | ||||||||||||||||||||||||||||||||
| 413 | 2 | ▶ | my ($self, $exc_ref) = @_; | ||||||||||||||||||||||||||||||
|
Subroutine
exception: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||||||||||||||||||||||||
| 414 | |||||||||||||||||||||||||||||||||
| 415 | #FIXME the only on_exception callback get dereferenced value | ||||||||||||||||||||||||||||||||
| 416 | # could it be changed without damage? | ||||||||||||||||||||||||||||||||
| 417 | 2 | my $exception = Storable::thaw($$exc_ref); | |||||||||||||||||||||||||||||||
| 418 | 2 | ▶ | $self->{on_exception}->($$exception) if $self->{on_exception}; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 419 | 2 | return; | |||||||||||||||||||||||||||||||
| 420 | } ## end sub exception | ||||||||||||||||||||||||||||||||
| 421 | |||||||||||||||||||||||||||||||||
| 422 | =head2 complete($result) | ||||||||||||||||||||||||||||||||
| 423 | |||||||||||||||||||||||||||||||||
| 424 | C<$result> a reference profided to on_complete cb | ||||||||||||||||||||||||||||||||
| 425 | |||||||||||||||||||||||||||||||||
| 426 | =cut | ||||||||||||||||||||||||||||||||
| 427 | |||||||||||||||||||||||||||||||||
| 428 | sub complete { | ||||||||||||||||||||||||||||||||
| 429 | 2 | ▶ | my ($self, $result_ref) = @_; | ||||||||||||||||||||||||||||||
|
Subroutine
complete: called CC=4 SCAR=14.3
Pod
documented
| |||||||||||||||||||||||||||||||||
| 430 | 2 | ▶ | return if $self->{is_finished}; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 431 | |||||||||||||||||||||||||||||||||
| 432 | 2 | $self->{is_finished} = 'complete'; | |||||||||||||||||||||||||||||||
| 433 | |||||||||||||||||||||||||||||||||
| 434 | 2 | $self->run_hook('complete', $self); | |||||||||||||||||||||||||||||||
| 435 | |||||||||||||||||||||||||||||||||
| 436 | 2 | ▶ | $self->{on_complete}->($result_ref) if $self->{on_complete}; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 437 | 2 | ▶ | $self->{on_post_hooks}->() if $self->{on_post_hooks}; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 438 | 2 | $self->wipe; | |||||||||||||||||||||||||||||||
| 439 | } ## end sub complete | ||||||||||||||||||||||||||||||||
| 440 | |||||||||||||||||||||||||||||||||
| 441 | =head2 status() | ||||||||||||||||||||||||||||||||
| 442 | |||||||||||||||||||||||||||||||||
| 443 | =cut | ||||||||||||||||||||||||||||||||
| 444 | |||||||||||||||||||||||||||||||||
| 445 | sub status { | ||||||||||||||||||||||||||||||||
| 446 | 2 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||
|
Subroutine
status: called CC=3 SCAR=11.3
Pod
documented
| |||||||||||||||||||||||||||||||||
| 447 | 2 | ▶ | return if $self->{is_finished}; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 448 | 2 | ▶ | return unless $self->{on_status}; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 449 | 2 | my ($nu, $de) = @_; | |||||||||||||||||||||||||||||||
| 450 | 2 | $self->{on_status}->($nu, $de); | |||||||||||||||||||||||||||||||
| 451 | } ## end sub status | ||||||||||||||||||||||||||||||||
| 452 | |||||||||||||||||||||||||||||||||
| 453 | =head2 data() | ||||||||||||||||||||||||||||||||
| 454 | |||||||||||||||||||||||||||||||||
| 455 | invokes C<on_data> callback if worker sends work_data notification. | ||||||||||||||||||||||||||||||||
| 456 | |||||||||||||||||||||||||||||||||
| 457 | =cut | ||||||||||||||||||||||||||||||||
| 458 | |||||||||||||||||||||||||||||||||
| 459 | sub data { | ||||||||||||||||||||||||||||||||
| 460 | 2 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||
|
Subroutine
data: called CC=3 SCAR=11.4
Pod
documented
| |||||||||||||||||||||||||||||||||
| 461 | 2 | ▶ | return if $self->{is_finished}; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 462 | 2 | my $result_ref = shift; | |||||||||||||||||||||||||||||||
| 463 | |||||||||||||||||||||||||||||||||
| 464 | 2 | ▶ | $self->{on_data}->($result_ref) if $self->{on_data}; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 465 | } ## end sub data | ||||||||||||||||||||||||||||||||
| 466 | |||||||||||||||||||||||||||||||||
| 467 | =head2 warning($message) | ||||||||||||||||||||||||||||||||
| 468 | |||||||||||||||||||||||||||||||||
| 469 | invokes C<on_warning> callback if worker sends work_warning notification. | ||||||||||||||||||||||||||||||||
| 470 | |||||||||||||||||||||||||||||||||
| 471 | =cut | ||||||||||||||||||||||||||||||||
| 472 | |||||||||||||||||||||||||||||||||
| 473 | sub warning { | ||||||||||||||||||||||||||||||||
| 474 | 1 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||
|
Subroutine
warning: called CC=3 SCAR=11.3
Pod
documented
| |||||||||||||||||||||||||||||||||
| 475 | 1 | ▶ | $self->{is_finished} && return; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 476 | 1 | ▶ | $self->{on_warning} || return; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 477 | |||||||||||||||||||||||||||||||||
| 478 | 1 | my $msg = shift; | |||||||||||||||||||||||||||||||
| 479 | |||||||||||||||||||||||||||||||||
| 480 | 1 | $self->{on_warning}->($msg); | |||||||||||||||||||||||||||||||
| 481 | } ## end sub warning | ||||||||||||||||||||||||||||||||
| 482 | |||||||||||||||||||||||||||||||||
| 483 | =head2 handle() | ||||||||||||||||||||||||||||||||
| 484 | |||||||||||||||||||||||||||||||||
| 485 | getter | ||||||||||||||||||||||||||||||||
| 486 | |||||||||||||||||||||||||||||||||
| 487 | =head2 handle($handle) | ||||||||||||||||||||||||||||||||
| 488 | |||||||||||||||||||||||||||||||||
| 489 | setter for the fully-qualified handle of form "IP:port//shandle" where | ||||||||||||||||||||||||||||||||
| 490 | |||||||||||||||||||||||||||||||||
| 491 | shandle is an opaque handle specific to the job server running on IP:port | ||||||||||||||||||||||||||||||||
| 492 | |||||||||||||||||||||||||||||||||
| 493 | =cut | ||||||||||||||||||||||||||||||||
| 494 | |||||||||||||||||||||||||||||||||
| 495 | sub handle { | ||||||||||||||||||||||||||||||||
| 496 | 2 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||
|
Subroutine
handle: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||||||||||||||||||||||||
| 497 | 2 | ▶ | if (@_) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 498 | 2 | $self->{handle} = shift; | |||||||||||||||||||||||||||||||
| 499 | } | ||||||||||||||||||||||||||||||||
| 500 | 2 | return $self->{handle}; | |||||||||||||||||||||||||||||||
| 501 | } ## end sub handle | ||||||||||||||||||||||||||||||||
| 502 | |||||||||||||||||||||||||||||||||
| 503 | #FIXME obsolete? | ||||||||||||||||||||||||||||||||
| 504 | |||||||||||||||||||||||||||||||||
| 505 | =head2 set_on_post_hooks($code) | ||||||||||||||||||||||||||||||||
| 506 | |||||||||||||||||||||||||||||||||
| 507 | =cut | ||||||||||||||||||||||||||||||||
| 508 | |||||||||||||||||||||||||||||||||
| 509 | sub set_on_post_hooks { | ||||||||||||||||||||||||||||||||
| 510 | 0 | ▶ | my ($self, $code) = @_; | ||||||||||||||||||||||||||||||
|
Subroutine
set_on_post_hooks: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||
| 511 | 0 | $self->{on_post_hooks} = $code; | |||||||||||||||||||||||||||||||
| 512 | } | ||||||||||||||||||||||||||||||||
| 513 | |||||||||||||||||||||||||||||||||
| 514 | =head2 wipe() | ||||||||||||||||||||||||||||||||
| 515 | |||||||||||||||||||||||||||||||||
| 516 | cleanup | ||||||||||||||||||||||||||||||||
| 517 | |||||||||||||||||||||||||||||||||
| 518 | =over | ||||||||||||||||||||||||||||||||
| 519 | |||||||||||||||||||||||||||||||||
| 520 | =item | ||||||||||||||||||||||||||||||||
| 521 | |||||||||||||||||||||||||||||||||
| 522 | on_post_hooks | ||||||||||||||||||||||||||||||||
| 523 | |||||||||||||||||||||||||||||||||
| 524 | =item | ||||||||||||||||||||||||||||||||
| 525 | |||||||||||||||||||||||||||||||||
| 526 | on_complete | ||||||||||||||||||||||||||||||||
| 527 | |||||||||||||||||||||||||||||||||
| 528 | =item | ||||||||||||||||||||||||||||||||
| 529 | |||||||||||||||||||||||||||||||||
| 530 | on_fail | ||||||||||||||||||||||||||||||||
| 531 | |||||||||||||||||||||||||||||||||
| 532 | =item | ||||||||||||||||||||||||||||||||
| 533 | |||||||||||||||||||||||||||||||||
| 534 | on_retry | ||||||||||||||||||||||||||||||||
| 535 | |||||||||||||||||||||||||||||||||
| 536 | =item | ||||||||||||||||||||||||||||||||
| 537 | |||||||||||||||||||||||||||||||||
| 538 | on_status | ||||||||||||||||||||||||||||||||
| 539 | |||||||||||||||||||||||||||||||||
| 540 | =item | ||||||||||||||||||||||||||||||||
| 541 | |||||||||||||||||||||||||||||||||
| 542 | hooks | ||||||||||||||||||||||||||||||||
| 543 | |||||||||||||||||||||||||||||||||
| 544 | =back | ||||||||||||||||||||||||||||||||
| 545 | |||||||||||||||||||||||||||||||||
| 546 | =cut | ||||||||||||||||||||||||||||||||
| 547 | |||||||||||||||||||||||||||||||||
| 548 | sub wipe { | ||||||||||||||||||||||||||||||||
| 549 | 7 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||
|
Subroutine
wipe: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||
| 550 | 7 | my @h = qw/ | |||||||||||||||||||||||||||||||
| 551 | on_post_hooks | ||||||||||||||||||||||||||||||||
| 552 | on_complete | ||||||||||||||||||||||||||||||||
| 553 | on_fail | ||||||||||||||||||||||||||||||||
| 554 | on_retry | ||||||||||||||||||||||||||||||||
| 555 | on_status | ||||||||||||||||||||||||||||||||
| 556 | hooks | ||||||||||||||||||||||||||||||||
| 557 | /; | ||||||||||||||||||||||||||||||||
| 558 | |||||||||||||||||||||||||||||||||
| 559 | 7 | foreach my $f (@h) { | |||||||||||||||||||||||||||||||
| 560 | 42 | $self->{$f} = undef; | |||||||||||||||||||||||||||||||
| 561 | } | ||||||||||||||||||||||||||||||||
| 562 | } ## end sub wipe | ||||||||||||||||||||||||||||||||
| 563 | |||||||||||||||||||||||||||||||||
| 564 | =head2 func() | ||||||||||||||||||||||||||||||||
| 565 | |||||||||||||||||||||||||||||||||
| 566 | =cut | ||||||||||||||||||||||||||||||||
| 567 | |||||||||||||||||||||||||||||||||
| 568 | sub func { | ||||||||||||||||||||||||||||||||
| 569 | 1 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||
|
Subroutine
func: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||
| 570 | 1 | return $self->{func}; | |||||||||||||||||||||||||||||||
| 571 | } | ||||||||||||||||||||||||||||||||
| 572 | |||||||||||||||||||||||||||||||||
| 573 | =head2 timeout() | ||||||||||||||||||||||||||||||||
| 574 | |||||||||||||||||||||||||||||||||
| 575 | getter | ||||||||||||||||||||||||||||||||
| 576 | |||||||||||||||||||||||||||||||||
| 577 | =head2 timeout($t) | ||||||||||||||||||||||||||||||||
| 578 | |||||||||||||||||||||||||||||||||
| 579 | setter | ||||||||||||||||||||||||||||||||
| 580 | |||||||||||||||||||||||||||||||||
| 581 | B<return> timeout | ||||||||||||||||||||||||||||||||
| 582 | =cut | ||||||||||||||||||||||||||||||||
| 583 | |||||||||||||||||||||||||||||||||
| 584 | sub timeout { | ||||||||||||||||||||||||||||||||
| 585 | 1 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||
|
Subroutine
timeout: called CC=2 SCAR=7.6
Pod
documented
| |||||||||||||||||||||||||||||||||
| 586 | 1 | ▶ | if (@_) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 587 | 0 | $self->{timeout} = shift; | |||||||||||||||||||||||||||||||
| 588 | } | ||||||||||||||||||||||||||||||||
| 589 | 1 | return $self->{timeout}; | |||||||||||||||||||||||||||||||
| 590 | } ## end sub timeout | ||||||||||||||||||||||||||||||||
| 591 | |||||||||||||||||||||||||||||||||
| 592 | =head2 mode() | ||||||||||||||||||||||||||||||||
| 593 | |||||||||||||||||||||||||||||||||
| 594 | B<return> mode in depends of background and priority | ||||||||||||||||||||||||||||||||
| 595 | |||||||||||||||||||||||||||||||||
| 596 | =cut | ||||||||||||||||||||||||||||||||
| 597 | |||||||||||||||||||||||||||||||||
| 598 | sub mode { | ||||||||||||||||||||||||||||||||
| 599 | 9 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||
|
Subroutine
mode: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||
| 600 | 9 | my $mode = "submit_job"; | |||||||||||||||||||||||||||||||
| 601 | 9 | ▶ | if ($self->_priority() ne "normal") { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 602 | 6 | $mode .= "_" . $self->_priority(); | |||||||||||||||||||||||||||||||
| 603 | } | ||||||||||||||||||||||||||||||||
| 604 | |||||||||||||||||||||||||||||||||
| 605 | 9 | ▶ | if ($self->{background}) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 606 | 4 | $mode .= "_bg"; | |||||||||||||||||||||||||||||||
| 607 | } | ||||||||||||||||||||||||||||||||
| 608 | |||||||||||||||||||||||||||||||||
| 609 | 9 | return $mode; | |||||||||||||||||||||||||||||||
| 610 | } ## end sub mode | ||||||||||||||||||||||||||||||||
| 611 | |||||||||||||||||||||||||||||||||
| 612 | #=head2 _priority($priority) | ||||||||||||||||||||||||||||||||
| 613 | # | ||||||||||||||||||||||||||||||||
| 614 | #set/get priority | ||||||||||||||||||||||||||||||||
| 615 | # | ||||||||||||||||||||||||||||||||
| 616 | #valid C<$priority> value | ||||||||||||||||||||||||||||||||
| 617 | # | ||||||||||||||||||||||||||||||||
| 618 | #=over | ||||||||||||||||||||||||||||||||
| 619 | # | ||||||||||||||||||||||||||||||||
| 620 | #=item | ||||||||||||||||||||||||||||||||
| 621 | # | ||||||||||||||||||||||||||||||||
| 622 | #high | ||||||||||||||||||||||||||||||||
| 623 | # | ||||||||||||||||||||||||||||||||
| 624 | #=item | ||||||||||||||||||||||||||||||||
| 625 | # | ||||||||||||||||||||||||||||||||
| 626 | #normal (default) | ||||||||||||||||||||||||||||||||
| 627 | # | ||||||||||||||||||||||||||||||||
| 628 | #=item | ||||||||||||||||||||||||||||||||
| 629 | # | ||||||||||||||||||||||||||||||||
| 630 | #low | ||||||||||||||||||||||||||||||||
| 631 | # | ||||||||||||||||||||||||||||||||
| 632 | #=back | ||||||||||||||||||||||||||||||||
| 633 | # | ||||||||||||||||||||||||||||||||
| 634 | #=cut | ||||||||||||||||||||||||||||||||
| 635 | |||||||||||||||||||||||||||||||||
| 636 | sub _priority { | ||||||||||||||||||||||||||||||||
| 637 | 35 | ▶ | my ($self, $priority) = @_; | ||||||||||||||||||||||||||||||
|
Subroutine
_priority: called CC=5 SCAR=16.1
| |||||||||||||||||||||||||||||||||
| 638 | 35 | ▶ | if ($self->{high_priority}) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 639 | 2 | warn <<'HERE'; | |||||||||||||||||||||||||||||||
| 640 | Gearman::Task key high_priority is deprecated. | ||||||||||||||||||||||||||||||||
| 641 | Use priority => "high" instead | ||||||||||||||||||||||||||||||||
| 642 | HERE | ||||||||||||||||||||||||||||||||
| 643 | 2 | $self->{priority} = "high"; | |||||||||||||||||||||||||||||||
| 644 | 2 | delete($self->{high_priority}); | |||||||||||||||||||||||||||||||
| 645 | } ## end if ($self->{high_priority...}) | ||||||||||||||||||||||||||||||||
| 646 | |||||||||||||||||||||||||||||||||
| 647 | 35 | ▶ | if ($priority) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 648 | 6 | ▶ | $priority =~ /^(high|normal|low)$/ | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 649 | || Carp::croak "unsupported priority value"; | ||||||||||||||||||||||||||||||||
| 650 | 6 | $self->{priority} = $priority; | |||||||||||||||||||||||||||||||
| 651 | } | ||||||||||||||||||||||||||||||||
| 652 | 35 | ▶ | $self->{priority} ||= "normal"; | ||||||||||||||||||||||||||||||
|
Condition100%2/2
$self->{"priority"} ||= "normal"
MC/DC100%1/1
$self->{"priority"} ||= "normal"
$self->{"priority"}
Truth table100%2/2
A
A= $self->{"priority"}
| |||||||||||||||||||||||||||||||||
| 653 | |||||||||||||||||||||||||||||||||
| 654 | 35 | return $self->{priority}; | |||||||||||||||||||||||||||||||
| 655 | } ## end sub _priority | ||||||||||||||||||||||||||||||||
| 656 | |||||||||||||||||||||||||||||||||
| 657 | 7 | 1; | |||||||||||||||||||||||||||||||
| 658 | __END__ | ||||||||||||||||||||||||||||||||