| 1 | package Job::Machine::Worker; | ||||||||||||||||||||||||||||||||
| 2 | 2 | $Job::Machine::Worker::VERSION = '0.22'; | |||||||||||||||||||||||||||||||
| 3 | 2 | ▶ | use strict; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 4 | 2 | ▶ | use warnings; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||
| 6 | 2 | ▶ | use base 'Job::Machine::Base'; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||
| 8 | sub reply { | ||||||||||||||||||||||||||||||||
| 9 | 0 | ▶ | my ($self,$data,$queue) = @_; | ||||||||||||||||||||||||||||||
|
Subroutine
reply: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||
| 10 | 0 | my $db = $self->db; | |||||||||||||||||||||||||||||||
| 11 | 0 | ▶ | $queue ||= $self->{queue}; | ||||||||||||||||||||||||||||||
|
Condition0%0/3
$queue ||= $self->{"queue"}
MC/DC0%0/2
$queue ||= $self->{"queue"}
$queue
$self->{"queue"}
Truth table0%0/3
A ||= B
A= $queueB= $self->{"queue"}
| |||||||||||||||||||||||||||||||||
| 12 | 0 | $self->result($data,$queue); | |||||||||||||||||||||||||||||||
| 13 | 0 | my $task_id = $db->task_id; | |||||||||||||||||||||||||||||||
| 14 | ## Payload: Status of result, result id... | ||||||||||||||||||||||||||||||||
| 15 | 0 | $db->notify(queue => $task_id, reply => 1); | |||||||||||||||||||||||||||||||
| 16 | 0 | return $task_id; | |||||||||||||||||||||||||||||||
| 17 | } | ||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||
| 19 | sub result { | ||||||||||||||||||||||||||||||||
| 20 | 0 | ▶ | my ($self,$data,$queue) = @_; | ||||||||||||||||||||||||||||||
|
Subroutine
result: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||
| 21 | 0 | ▶ | $queue ||= $self->{queue}; | ||||||||||||||||||||||||||||||
|
Condition0%0/3
$queue ||= $self->{"queue"}
MC/DC0%0/2
$queue ||= $self->{"queue"}
$queue
$self->{"queue"}
Truth table0%0/3
A ||= B
A= $queueB= $self->{"queue"}
| |||||||||||||||||||||||||||||||||
| 22 | 0 | $self->db->insert_result($data,$queue); | |||||||||||||||||||||||||||||||
| 23 | 0 | $self->db->set_task_status(200); | |||||||||||||||||||||||||||||||
| 24 | } | ||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||
| 26 | sub error_result { | ||||||||||||||||||||||||||||||||
| 27 | 0 | ▶ | my ($self,$data,$queue) = @_; | ||||||||||||||||||||||||||||||
|
Subroutine
error_result: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||
| 28 | 0 | ▶ | $queue ||= $self->{queue}; | ||||||||||||||||||||||||||||||
|
Condition0%0/3
$queue ||= $self->{"queue"}
MC/DC0%0/2
$queue ||= $self->{"queue"}
$queue
$self->{"queue"}
Truth table0%0/3
A ||= B
A= $queueB= $self->{"queue"}
| |||||||||||||||||||||||||||||||||
| 29 | 0 | $self->db->insert_result($data,$queue); | |||||||||||||||||||||||||||||||
| 30 | } | ||||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||||
| 32 | sub receive { | ||||||||||||||||||||||||||||||||
| 33 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||
|
Subroutine
receive: not called CC=5 SCAR=34.0
Pod
documented
| |||||||||||||||||||||||||||||||||
| 34 | 0 | $self->startup; | |||||||||||||||||||||||||||||||
| 35 | 0 | my $db = $self->{db}; | |||||||||||||||||||||||||||||||
| 36 | 0 | $self->subscribe($self->{queue}); | |||||||||||||||||||||||||||||||
| 37 | 0 | $self->_check_queue($self->{queue}); | |||||||||||||||||||||||||||||||
| 38 | 0 | ▶ | while ($self->keep_running && (my $notifies = $db->set_listen($self->timeout))) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$self->keep_running and my $notifies = $db->set_listen($self->timeout)
MC/DC0%0/2
$self->keep_running and my $notifies = $db->set_listen($self->timeout)
$self->keep_running
my $notifies = $db->set_listen($self->timeout)
Truth table0%0/3
A and B
A= $self->keep_runningB= my $notifies = $db->set_listen($self->timeout)
| |||||||||||||||||||||||||||||||||
| 39 | 0 | my ($queue,$pid) = @$notifies; | |||||||||||||||||||||||||||||||
| 40 | 0 | ▶ | $self->_do_chores() && next unless $queue; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/5
$queue || $self->_do_chores && (next)
$self->_do_chores and next
MC/DC0%0/2
$queue || $self->_do_chores && (next)
$queue
$self->_do_chores
Truth table0%0/3
A || B
A= $queueB= $self->_do_chores
| |||||||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||||||
| 42 | 0 | $self->_check_queue($self->{queue}); | |||||||||||||||||||||||||||||||
| 43 | } | ||||||||||||||||||||||||||||||||
| 44 | 0 | return; | |||||||||||||||||||||||||||||||
| 45 | }; | ||||||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||||||
| 47 | sub _check_queue { | ||||||||||||||||||||||||||||||||
| 48 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||
|
Subroutine
_check_queue: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||
| 49 | 0 | my $db = $self->{db}; | |||||||||||||||||||||||||||||||
| 50 | 0 | ▶ | while (my $task = $self->db->fetch_work_task) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 51 | ## log process call | ||||||||||||||||||||||||||||||||
| 52 | 0 | $self->process($task); | |||||||||||||||||||||||||||||||
| 53 | } | ||||||||||||||||||||||||||||||||
| 54 | } | ||||||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||||||
| 56 | sub _do_chores { | ||||||||||||||||||||||||||||||||
| 57 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||
|
Subroutine
_do_chores: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||
| 58 | 0 | my $db = $self->{db}; | |||||||||||||||||||||||||||||||
| 59 | my @chores = ( | ||||||||||||||||||||||||||||||||
| 60 | sub { | ||||||||||||||||||||||||||||||||
| 61 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||
| 62 | 0 | ▶ | my $number = $db->revive_tasks($self->max_runtime) || 0; | ||||||||||||||||||||||||||||||
|
Condition0%0/2
$db->revive_tasks($self->max_runtime) || 0
MC/DC0%0/1
$db->revive_tasks($self->max_runtime) || 0
$db->revive_tasks($self->max_runtime)
Truth table0%0/2
A
A= $db->revive_tasks($self->max_runtime)
| |||||||||||||||||||||||||||||||||
| 63 | 0 | $self->log("Revived tasks: $number"); | |||||||||||||||||||||||||||||||
| 64 | }, | ||||||||||||||||||||||||||||||||
| 65 | sub { | ||||||||||||||||||||||||||||||||
| 66 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||
| 67 | 0 | ▶ | my $number = $db->fail_tasks($self->retries) || 0; | ||||||||||||||||||||||||||||||
|
Condition0%0/2
$db->fail_tasks($self->retries) || 0
MC/DC0%0/1
$db->fail_tasks($self->retries) || 0
$db->fail_tasks($self->retries)
Truth table0%0/2
A
A= $db->fail_tasks($self->retries)
| |||||||||||||||||||||||||||||||||
| 68 | 0 | $self->log("Failed tasks: $number"); | |||||||||||||||||||||||||||||||
| 69 | }, | ||||||||||||||||||||||||||||||||
| 70 | sub { | ||||||||||||||||||||||||||||||||
| 71 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||
| 72 | 0 | ▶ | my $number = $db->remove_tasks($self->remove_after) || 0; | ||||||||||||||||||||||||||||||
|
Condition0%0/2
$db->remove_tasks($self->remove_after) || 0
MC/DC0%0/1
$db->remove_tasks($self->remove_after) || 0
$db->remove_tasks($self->remove_after)
Truth table0%0/2
A
A= $db->remove_tasks($self->remove_after)
| |||||||||||||||||||||||||||||||||
| 73 | 0 | $self->log("Removed tasks: $number"); | |||||||||||||||||||||||||||||||
| 74 | }, | ||||||||||||||||||||||||||||||||
| 75 | 0 | ); | |||||||||||||||||||||||||||||||
| 76 | 0 | my $chore = $chores[int(rand(@chores))]; | |||||||||||||||||||||||||||||||
| 77 | 0 | $self->$chore; | |||||||||||||||||||||||||||||||
| 78 | } | ||||||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||||||
| 80 | ▶ | sub startup {} | |||||||||||||||||||||||||||||||
|
Subroutine
startup: not called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||||||
| 82 | 0 | ▶ | sub process {die 'Subclasss me!'} | ||||||||||||||||||||||||||||||
|
Subroutine
process: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||||||
| 84 | 0 | ▶ | sub max_runtime {return 30*60} | ||||||||||||||||||||||||||||||
|
Subroutine
max_runtime: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||||||
| 86 | 0 | ▶ | sub timeout {return 300} | ||||||||||||||||||||||||||||||
|
Subroutine
timeout: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||||||
| 88 | 0 | ▶ | sub retries {return 3} | ||||||||||||||||||||||||||||||
|
Subroutine
retries: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||||||
| 90 | 0 | ▶ | sub remove_after {return 30} | ||||||||||||||||||||||||||||||
|
Subroutine
remove_after: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||||||
| 92 | 0 | ▶ | sub keep_running {return 1} | ||||||||||||||||||||||||||||||
|
Subroutine
keep_running: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||||||
| 94 | 2 | 1; | |||||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||||||
| 96 | __END__ | ||||||||||||||||||||||||||||||||