]> git.proxmox.com Git - pve-ha-manager.git/commitdiff
implement sleep_until to add constant delay
authorDietmar Maurer <dietmar@proxmox.com>
Sat, 29 Nov 2014 13:01:50 +0000 (14:01 +0100)
committerDietmar Maurer <dietmar@proxmox.com>
Sat, 29 Nov 2014 13:01:50 +0000 (14:01 +0100)
PVE/HA/SimEnv.pm
pve-ha-manager

index 287aa1da7f04c42f6b3a532295725b5e57679a0a..9ed16f6dc89920d15c7543731819c6ca8daa4f00 100644 (file)
@@ -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;
 }
index 8cb182c16969c5be45886c09525271761b602cbe..afad98902b366c5510bc81580f97e73d84022aa8 100755 (executable)
@@ -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 {