| 1 | package TaskPipe::PortManager; | ||||||||||
| 2 | |||||||||||
| 3 | 38 | ▶ | use Moose; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 38 | ▶ | use Log::Log4perl; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | 38 | ▶ | use Net::EmptyPort; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | 38 | ▶ | use Try::Tiny; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | |||||||||||
| 8 | 38 | has base_port => (is => 'rw', isa => 'Int'); | |||||||||
| 9 | 38 | has process_name => (is => 'rw', isa => 'Str'); | |||||||||
| 10 | |||||||||||
| 11 | 38 | has gm => (is => 'rw', isa => 'TaskPipe::SchemaManager'); | |||||||||
| 12 | has run_info => (is => 'rw', isa => 'TaskPipe::RunInfo', default => sub{ | ||||||||||
| 13 | 34 | ▶ | TaskPipe::RunInfo->new | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 14 | 38 | }); | |||||||||
| 15 | |||||||||||
| 16 | |||||||||||
| 17 | sub get_new_port_number{ | ||||||||||
| 18 | 0 | ▶ | my $self = shift; | ||||||||
|
Subroutine
get_new_port_number: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||
| 19 | |||||||||||
| 20 | 0 | my $err; | |||||||||
| 21 | my $port; | ||||||||||
| 22 | 0 | my $base_port = $self->base_port; | |||||||||
| 23 | 0 | my $port_row; | |||||||||
| 24 | 0 | my $success = 0; | |||||||||
| 25 | |||||||||||
| 26 | 0 | ▶ | while ( ! $success ){ | ||||||||
|
Branch: 1 branch
| |||||||||||
| 27 | |||||||||||
| 28 | 0 | ▶ | do { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 29 | 0 | $port = Net::EmptyPort::empty_port( $base_port ); | |||||||||
| 30 | 0 | $port_row = $self->gm->table('port')->find_or_new({ | |||||||||
| 31 | port => $port, | ||||||||||
| 32 | }, { | ||||||||||
| 33 | key => 'primary' | ||||||||||
| 34 | }); | ||||||||||
| 35 | 0 | $base_port = $port + 1; | |||||||||
| 36 | } while( $port_row->in_storage ); | ||||||||||
| 37 | |||||||||||
| 38 | try { | ||||||||||
| 39 | |||||||||||
| 40 | 0 | ▶ | $port_row->insert; | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 41 | 0 | $port_row->update({ | |||||||||
| 42 | job_id => $self->run_info->job_id, | ||||||||||
| 43 | thread_id => $self->run_info->thread_id, | ||||||||||
| 44 | process_name => $self->process_name | ||||||||||
| 45 | }); | ||||||||||
| 46 | 0 | $success = 1; | |||||||||
| 47 | |||||||||||
| 48 | } catch { | ||||||||||
| 49 | |||||||||||
| 50 | 0 | ▶ | $base_port = $port + 1; | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 51 | 0 | $success = 0; | |||||||||
| 52 | |||||||||||
| 53 | 0 | }; | |||||||||
| 54 | |||||||||||
| 55 | } | ||||||||||
| 56 | |||||||||||
| 57 | 0 | return $port; | |||||||||
| 58 | } | ||||||||||
| 59 | |||||||||||
| 60 | |||||||||||
| 61 | sub get_port{ | ||||||||||
| 62 | 0 | ▶ | my ($self) = @_; | ||||||||
|
Subroutine
get_port: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||
| 63 | |||||||||||
| 64 | 0 | my $port_row = $self->gm->table('port')->find({ | |||||||||
| 65 | job_id => $self->run_info->job_id, | ||||||||||
| 66 | process_name => $self->process_name, | ||||||||||
| 67 | thread_id => $self->run_info->thread_id | ||||||||||
| 68 | }); | ||||||||||
| 69 | |||||||||||
| 70 | 0 | ▶ | return $port_row->port if $port_row; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 71 | 0 | return +$self->get_new_port_number; | |||||||||
| 72 | } | ||||||||||
| 73 | |||||||||||
| 74 | |||||||||||
| 75 | |||||||||||
| 76 | |||||||||||
| 77 | sub clear_ports{ | ||||||||||
| 78 | 33 | ▶ | my ($self,$job_id) = @_; | ||||||||
|
Subroutine
clear_ports: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 79 | |||||||||||
| 80 | 33 | my $ports_rs = $self->gm->table('port')->search({ | |||||||||
| 81 | job_id => $job_id | ||||||||||
| 82 | })->delete_all; | ||||||||||
| 83 | |||||||||||
| 84 | } | ||||||||||
| 85 | |||||||||||
| 86 | =head1 NAME | ||||||||||
| 87 | |||||||||||
| 88 | TaskPipe::PortManager - manage ports for TaskPipe | ||||||||||
| 89 | |||||||||||
| 90 | =head1 DESCRIPTION | ||||||||||
| 91 | |||||||||||
| 92 | It is not recommended to use this module directly. See the general manpages for TaskPipe. | ||||||||||
| 93 | |||||||||||
| 94 | =head1 AUTHOR | ||||||||||
| 95 | |||||||||||
| 96 | Tom Gracey <tomgracey@gmail.com> | ||||||||||
| 97 | |||||||||||
| 98 | =head1 COPYRIGHT AND LICENSE | ||||||||||
| 99 | |||||||||||
| 100 | Copyright (c) Tom Gracey 2018 | ||||||||||
| 101 | |||||||||||
| 102 | TaskPipe is free software, licensed under | ||||||||||
| 103 | |||||||||||
| 104 | The GNU Public License Version 3 | ||||||||||
| 105 | |||||||||||
| 106 | =cut | ||||||||||
| 107 | |||||||||||
| 108 | 38 | __PACKAGE__->meta->make_immutable; | |||||||||
| 109 | 38 | 1; | |||||||||