Skip to content

Commit

Permalink
wip: properly store timeout in constant
Browse files Browse the repository at this point in the history
  • Loading branch information
frankiejol committed May 2, 2024
1 parent 08a8c12 commit b6c6943
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
8 changes: 7 additions & 1 deletion lib/Ravada/VM.pm
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ our $MIN_DISK_MB = 1024 * 1024;
our $CACHE_TIMEOUT = 60;
our $FIELD_TIMEOUT = '_data_timeout';

our $TIMEOUT_DOWN_CACHE = 120;

our %VM; # cache Virtual Manager Connection
our %SSH;

Expand Down Expand Up @@ -343,9 +345,13 @@ sub _connect {
return $result;
}

sub timeout_down_cache($self) {
return $TIMEOUT_DOWN_CACHE;
}

sub _around_connect($orig, $self) {

if ($self->_data('cached_down') && time-$self->_data('cached_down')<120) {
if ($self->_data('cached_down') && time-$self->_data('cached_down')< $self->timeout_down_cache()) {
return;
}
my $result = $self->$orig();
Expand Down
2 changes: 1 addition & 1 deletion lib/Ravada/VM/KVM.pm
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ sub _connect {
} else {
confess "Error: You can't connect to remote VMs in readonly mode"
if $self->readonly;
if ($self->_data('cached_down') && time-$self->_data('cached_down')<120) {
if ($self->_data('cached_down') && time-$self->_data('cached_down')<$self->timeout_down_cache()) {
return;
}
my $transport = 'ssh';
Expand Down

0 comments on commit b6c6943

Please sign in to comment.