| 1 | package Schedule::Pluggable::Status; | ||||||||||||||||||||||||||||
| 2 | 3 | ▶ | use Moose::Role; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 3 | 3 | ▶ | use English; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 3 | ▶ | use Fcntl qw(:DEFAULT :flock); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 3 | ▶ | use Carp qw/ carp /; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 3 | ▶ | use Data::Dumper; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 3 | ▶ | use POSIX qw/ strftime /; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 3 | $Data::Dumper::Sortkeys = 1; | |||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | 3 | has status => ( is => 'rw', | |||||||||||||||||||||||||||
| 11 | isa => 'HashRef', | ||||||||||||||||||||||||||||
| 12 | lazy => 1, | ||||||||||||||||||||||||||||
| 13 | reader => '_get_status', | ||||||||||||||||||||||||||||
| 14 | writer => '_set_status', | ||||||||||||||||||||||||||||
| 15 | builder => '_initialise_status', | ||||||||||||||||||||||||||||
| 16 | ); | ||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | 1 | ▶ | sub _initialise_status { | ||||||||||||||||||||||||||
|
Subroutine
_initialise_status: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 19 | 1 | my $self = shift; | |||||||||||||||||||||||||||
| 20 | return { | ||||||||||||||||||||||||||||
| 21 | 1 | Jobs => {}, | |||||||||||||||||||||||||||
| 22 | TotalJobs => 0, | ||||||||||||||||||||||||||||
| 23 | TotalQueued => 0, | ||||||||||||||||||||||||||||
| 24 | TotalStarted => 0, | ||||||||||||||||||||||||||||
| 25 | TotalFinished => 0, | ||||||||||||||||||||||||||||
| 26 | TotalSucceeded => 0, | ||||||||||||||||||||||||||||
| 27 | TotalFailed => 0, | ||||||||||||||||||||||||||||
| 28 | Groups => {}, | ||||||||||||||||||||||||||||
| 29 | Ready_to_Run => {}, | ||||||||||||||||||||||||||||
| 30 | Ids => {}, | ||||||||||||||||||||||||||||
| 31 | Pids => {}, | ||||||||||||||||||||||||||||
| 32 | }; | ||||||||||||||||||||||||||||
| 33 | } | ||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||
| 35 | 7 | ▶ | sub _update_status { | ||||||||||||||||||||||||||
|
Subroutine
_update_status: called CC=29 SCAR=43.1
| |||||||||||||||||||||||||||||
| 36 | 7 | my $self = shift; | |||||||||||||||||||||||||||
| 37 | 7 | my $no = 1; | |||||||||||||||||||||||||||
| 38 | 7 | my ($key, $params) = @_; | |||||||||||||||||||||||||||
| 39 | 7 | my $status = $self->_get_status(); | |||||||||||||||||||||||||||
| 40 | my $job_name = $key->{name} ? $key->{name} | ||||||||||||||||||||||||||||
| 41 | 7 | ▶ | : $status->{Ids}{$key->{id}}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 42 | # warn Data::Dumper->Dump([$key, $params, $status->{Ids}],[qw/$key $params $status->{Ids}/]) unless $job_name; | ||||||||||||||||||||||||||||
| 43 | 7 | ▶ | $job_name ||= "Job".$key->{id}; | ||||||||||||||||||||||||||
|
Condition50%1/2
$job_name ||= 'Job' . $key->{"id"}
MC/DC0%0/1
$job_name ||= 'Job' . $key->{"id"}
$job_name
Truth table50%1/2
A
A= $job_name
| |||||||||||||||||||||||||||||
| 44 | 7 | ▶ | return if $job_name eq 'MonitorJobs'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 45 | 4 | foreach my $p (keys %{ $params } ) { | |||||||||||||||||||||||||||
| 46 | 6 | ▶ | $status->{Ids}{$params->{$p}} = $job_name if $p eq "Id"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 47 | 6 | ▶ | $status->{Queued}{$job_name} = $params->{$p} if $p eq "Queued"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 48 | 6 | ▶ | $status->{Pids}{$job_name} = $params->{$p} if $p eq "Pid"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 49 | 6 | ▶ | $status->{TotalQueued}++ if $p eq "Id"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 50 | 6 | ▶ | $status->{TotalStarted}++ if $p eq "timestarted"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 51 | 6 | ▶ | $status->{Running}{$job_name} = strftime('%d/%m/%Y %H:%M:%S', localtime(time())) if $p eq "timestarted"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 52 | 6 | ▶ | $status->{TotalFinished}++ if $p eq "timefinished"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 53 | # print Data::Dumper->Dump([$status->{Running}], [qw/$status->{Running}/]); | ||||||||||||||||||||||||||||
| 54 | 6 | ▶ | delete $status->{Running}{$job_name} if $p eq "timefinished"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 55 | 6 | ▶ | delete $status->{Queued}{$job_name} if $p eq "timestarted"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 56 | # print Data::Dumper->Dump([$status->{Running}], [qw/$status->{Running}/]); | ||||||||||||||||||||||||||||
| 57 | 6 | ▶ | if (ref $params->{$p} eq "ARRAY") { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 58 | 0 | ▶ | $status->{Jobs}{$job_name}{$p} ||= []; | ||||||||||||||||||||||||||
|
Condition0%0/2
$status->{"Jobs"}{$job_name}{$p} ||= []
MC/DC0%0/1
$status->{"Jobs"}{$job_name}{$p} ||= []
$status->{"Jobs"}{$job_name}{$p}
Truth table0%0/2
A
A= $status->{"Jobs"}{$job_name}{$p}
| |||||||||||||||||||||||||||||
| 59 | 0 | push(@{ $status->{Jobs}{$job_name}{$p} }, @{ $params->{$p} }); | |||||||||||||||||||||||||||
| 60 | } | ||||||||||||||||||||||||||||
| 61 | else { | ||||||||||||||||||||||||||||
| 62 | 6 | $status->{Jobs}{$job_name}{$p} = $params->{$p}; | |||||||||||||||||||||||||||
| 63 | } | ||||||||||||||||||||||||||||
| 64 | } | ||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||
| 66 | 4 | my @jobs_to_queue = (); | |||||||||||||||||||||||||||
| 67 | 4 | ▶ | if (defined($params->{status})) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 68 | 1 | ▶ | if ($params->{status} != 0) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 69 | 0 | $status->{TotalFailed}++; | |||||||||||||||||||||||||||
| 70 | 0 | ▶ | $status->{Jobs}{$job_name}{stderr} ||= [ pop(@{ $status->{Jobs}{$job_name}{stdout} }) ]; | ||||||||||||||||||||||||||
|
Condition0%0/2
$status->{"Jobs"}{$job_name}{"stderr"} ||= [pop @{$$status{"Jobs"}{$job_name}{"stdout"};}]
MC/DC0%0/1
$status->{"Jobs"}{$job_name}{"stderr"} ||= [pop @{$$status{"Jobs"}{$job_name}{"stdout"};}]
$status->{"Jobs"}{$job_name}{"stderr"}
Truth table0%0/2
A
A= $status->{"Jobs"}{$job_name}{"stderr"}
| |||||||||||||||||||||||||||||
| 71 | 0 | ▶ | $status->{Jobs}{$job_name}{stderr} ||= []; | ||||||||||||||||||||||||||
|
Condition0%0/2
$status->{"Jobs"}{$job_name}{"stderr"} ||= []
MC/DC0%0/1
$status->{"Jobs"}{$job_name}{"stderr"} ||= []
$status->{"Jobs"}{$job_name}{"stderr"}
Truth table0%0/2
A
A= $status->{"Jobs"}{$job_name}{"stderr"}
| |||||||||||||||||||||||||||||
| 72 | $status->{Failed}{$job_name} = { status => $params->{status}, | ||||||||||||||||||||||||||||
| 73 | 0 | stderr => [ @{ $status->{Jobs}{$job_name}{stderr} } ] }; | |||||||||||||||||||||||||||
| 74 | } | ||||||||||||||||||||||||||||
| 75 | else { | ||||||||||||||||||||||||||||
| 76 | 1 | $status->{TotalSucceeded}++; | |||||||||||||||||||||||||||
| 77 | 1 | my @jobs = keys %{ $status->{Jobs} }; | |||||||||||||||||||||||||||
| 78 | 1 | JOB: foreach my $job (@jobs) { | |||||||||||||||||||||||||||
| 79 | 1 | ▶ | next JOB if $job eq $job_name; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 80 | 0 | ▶ | if ($status->{Jobs}{$job}{prerequisites}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 81 | 0 | my %p = %{ $status->{Jobs}{$job}{prerequisites} }; | |||||||||||||||||||||||||||
| 82 | 0 | ▶ | if (exists ($p{$job_name} )) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 83 | 0 | $status->{Jobs}{$job}{prerequisites}{$job_name} = strftime('%d/%m/%Y %H:%M:%S', localtime(time())); | |||||||||||||||||||||||||||
| 84 | 0 | $status->{Jobs}{$job}{ pending_prerequisites }--; | |||||||||||||||||||||||||||
| 85 | } | ||||||||||||||||||||||||||||
| 86 | 0 | ▶ | if (!defined($status->{Jobs}{$job}{timestarted}) and | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
not defined $status->{"Jobs"}{$job}{"timestarted"} and $status->{"Jobs"}{$job}{"pending_prerequisites"} == 0
MC/DC0%0/2
not defined $status->{"Jobs"}{$job}{"timestarted"} and $status->{"Jobs"}{$job}{"pending_prerequisites"} == 0
not defined $status->{"Jobs"}{$job}{"timestarted"}
$status->{"Jobs"}{$job}{"pending_prerequisites"} == 0
Truth table0%0/3
not(A) and B
A= not defined $status->{"Jobs"}{$job}{"timestarted"}B= $status->{"Jobs"}{$job}{"pending_prerequisites"} == 0
| |||||||||||||||||||||||||||||
| 87 | $status->{Jobs}{$job}{ pending_prerequisites } == 0) { | ||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||
| 89 | 0 | push(@jobs_to_queue, {name => $job, command => $status->{Jobs}{$job}{command} }); | |||||||||||||||||||||||||||
| 90 | } | ||||||||||||||||||||||||||||
| 91 | #$self->queue_jobs($status->{Jobs}{$job}) if $status->{Jobs}{$job}{ pending_prerequisites } == 0; | ||||||||||||||||||||||||||||
| 92 | } | ||||||||||||||||||||||||||||
| 93 | } | ||||||||||||||||||||||||||||
| 94 | } | ||||||||||||||||||||||||||||
| 95 | } | ||||||||||||||||||||||||||||
| 96 | 4 | $status->{LastUpdate} = strftime('%d/%m/%Y %H:%M:%S', localtime(time())); | |||||||||||||||||||||||||||
| 97 | 4 | $self->_set_status($status); | |||||||||||||||||||||||||||
| 98 | 4 | ▶ | if (scalar(@jobs_to_queue) > 0) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 99 | 0 | $self->_queue_jobs(@jobs_to_queue); | |||||||||||||||||||||||||||
| 100 | } | ||||||||||||||||||||||||||||
| 101 | 4 | ▶ | if ($status->{TotalFailed} > 0 or $status->{TotalFinished} >= $status->{TotalJobs}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$status->{"TotalFailed"} > 0 or $status->{"TotalFinished"} >= $status->{"TotalJobs"}
MC/DC50%1/2
$status->{"TotalFailed"} > 0 or $status->{"TotalFinished"} >= $status->{"TotalJobs"}
$status->{"TotalFailed"} > 0
$status->{"TotalFinished"} >= $status->{"TotalJobs"}
Truth table66%2/3
A or B
A= $status->{"TotalFailed"} > 0B= $status->{"TotalFinished"} >= $status->{"TotalJobs"}
| |||||||||||||||||||||||||||||
| 102 | 2 | system("touch ".$status->{EndOfScheduleFile}); | |||||||||||||||||||||||||||
| 103 | } | ||||||||||||||||||||||||||||
| 104 | } | ||||||||||||||||||||||||||||
| 105 | 3 | 1; | |||||||||||||||||||||||||||
| 106 | __END__ | ||||||||||||||||||||||||||||