« blib/lib/HPC/Runner/Command/Logger/JSON.pm
↑ Summary
blib/lib/HPC/Runner/Command/stats/Logger/JSON/Summary/JSONOutput.pm »
| 1 | package HPC::Runner::Command::execute_job::Logger::Lock; | ||||||||||
| 2 | |||||||||||
| 3 | 1 | ▶ | use Moose::Role; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 1 | ▶ | use namespace::autoclean; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | |||||||||||
| 6 | 1 | ▶ | use Try::Tiny; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | 1 | ▶ | use Time::HiRes; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | 1 | ▶ | use File::Spec; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | 1 | ▶ | use MooseX::Types::Path::Tiny qw/Path Paths AbsPath AbsFile/; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 10 | |||||||||||
| 11 | has 'lock_file' => ( | ||||||||||
| 12 | is => 'rw', | ||||||||||
| 13 | isa => Path, | ||||||||||
| 14 | lazy => 1, | ||||||||||
| 15 | coerce => 1, | ||||||||||
| 16 | required => 1, | ||||||||||
| 17 | default => sub { | ||||||||||
| 18 | 0 | ▶ | my $self = shift; | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 19 | 0 | my $file = File::Spec->catdir( $self->data_dir, '.lock' ); | |||||||||
| 20 | 0 | return $file; | |||||||||
| 21 | }, | ||||||||||
| 22 | 1 | ); | |||||||||
| 23 | |||||||||||
| 24 | 1 | has 'logger' => ( | |||||||||
| 25 | is => 'rw', | ||||||||||
| 26 | isa => 'Str', | ||||||||||
| 27 | default => 'command_log', | ||||||||||
| 28 | ); | ||||||||||
| 29 | |||||||||||
| 30 | =head3 check_lock | ||||||||||
| 31 | |||||||||||
| 32 | Check to see if the lock exists | ||||||||||
| 33 | |||||||||||
| 34 | Have a max retry count to avoid infinite loops | ||||||||||
| 35 | |||||||||||
| 36 | =cut | ||||||||||
| 37 | |||||||||||
| 38 | sub check_lock { | ||||||||||
| 39 | 0 | ▶ | my $self = shift; | ||||||||
|
Subroutine
check_lock: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||
| 40 | |||||||||||
| 41 | 0 | my $max_retries = 500; | |||||||||
| 42 | 0 | my $x = 0; | |||||||||
| 43 | |||||||||||
| 44 | 0 | my $ret = 1; | |||||||||
| 45 | 0 | ▶ | while ( $self->lock_file->exists ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 46 | 0 | Time::HiRes::sleep(0.2); | |||||||||
| 47 | 0 | $x++; | |||||||||
| 48 | 0 | ▶ | if($x >= $max_retries){ | ||||||||
|
Branch: 1 branch
| |||||||||||
| 49 | 0 | $ret = 0; | |||||||||
| 50 | 0 | last; | |||||||||
| 51 | } | ||||||||||
| 52 | } | ||||||||||
| 53 | 0 | ▶ | if ( $x >= $max_retries ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 54 | 0 | $self->{$self->logger}->warn('Logger::JSON Error: We exited the lock!'); | |||||||||
| 55 | } | ||||||||||
| 56 | |||||||||||
| 57 | 0 | return $ret; | |||||||||
| 58 | } | ||||||||||
| 59 | |||||||||||
| 60 | sub write_lock { | ||||||||||
| 61 | 0 | ▶ | my $self = shift; | ||||||||
|
Subroutine
write_lock: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||
| 62 | |||||||||||
| 63 | try { | ||||||||||
| 64 | 0 | ▶ | $self->lock_file->touchpath; | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 65 | } | ||||||||||
| 66 | catch { | ||||||||||
| 67 | 0 | ▶ | $self->{$self->logger}->warn( | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 68 | 'Logger::JSON Error: We were not able to write ' | ||||||||||
| 69 | . $self->lock_file->stringify ); | ||||||||||
| 70 | 0 | }; | |||||||||
| 71 | } | ||||||||||
| 72 | |||||||||||
| 73 | 1 | 1; | |||||||||