From: Dietmar Maurer Date: Sat, 29 Nov 2014 13:01:50 +0000 (+0100) Subject: implement sleep_until to add constant delay X-Git-Url: https://git.proxmox.com/?a=commitdiff_plain;h=53a449bf4bfcd0b7d3b9cca2b6628f9c686a6b7c;p=pve-ha-manager.git implement sleep_until to add constant delay --- diff --git a/PVE/HA/SimEnv.pm b/PVE/HA/SimEnv.pm index 287aa1d..9ed16f6 100644 --- a/PVE/HA/SimEnv.pm +++ b/PVE/HA/SimEnv.pm @@ -81,9 +81,7 @@ sub loop_end_hook { my $delay = $cur_time - $self->{loop_start_time}; - die "loop take too long ($delay seconds)\n" if $delay > 20; - - $cur_time++; + die "loop take too long ($delay seconds)\n" if $delay > 30; die "simulation end\n" if $cur_time > $max_sim_time; } diff --git a/pve-ha-manager b/pve-ha-manager index 8cb182c..afad989 100755 --- a/pve-ha-manager +++ b/pve-ha-manager @@ -49,6 +49,15 @@ sub get_manager_lock { return 0; } +sub sleep_until { + my ($end_time) = @_; + + for (;;) { + my $cur_time = $haenv->get_time(); + return if $cur_time >= $end_time; + $haenv->sleep($end_time - $cur_time); + } +} $status = get_manager_status(); @@ -79,13 +88,23 @@ eval { } } elsif ($status eq 'quorate') { - # do work (max 10 seconds) + my $startime = $haenv->get_time(); + + my $max_time = 10; + + # do work (max_time seconds) + eval { + #print "DO WORK:$startime\n"; + # fixme: set alert timer + }; + + sleep_until($startime + $max_time); if (!get_manager_lock()) { set_manager_status('lost_quorum'); } } elsif ($status eq 'lost_quorum') { - die "lost_quorum"; + die "lost_quorum\n"; } elsif ($status eq 'halt') { die "halt\n"; } else {