From f9aae599d75d1d56206c1a32b1a7dbc06a90fb04 Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Tue, 16 May 2017 14:34:25 +0100 Subject: [PATCH] ts-hosts-allocate-Executive: Honour hostalloc_maxwait_max No functional change with existing flights. Signed-off-by: Ian Jackson --- ts-hosts-allocate-Executive | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/ts-hosts-allocate-Executive b/ts-hosts-allocate-Executive index 0987e2b5..9955cbad 100755 --- a/ts-hosts-allocate-Executive +++ b/ts-hosts-allocate-Executive @@ -56,6 +56,7 @@ if ($ENV{'OSSTEST_NOALLOCATE'}) { } # initialised by setup: +our $alloc_start_time; our $taskid; our %magictaskid; our $fi; @@ -109,6 +110,8 @@ END WHERE type='magic' AND refkey=? END } + + $alloc_start_time = time // die $!; } #---------- prepared sql statements ---------- @@ -748,6 +751,16 @@ sub attempt_allocation { logm("host allocation: successful, reporting to planner."); } else { logm("host allocation: planned start in $best->{Start} seconds."); + my $maxwait = $r{hostalloc_maxwait_max}; + if (defined $maxwait) { + # We quit if: + # * we have been waiting at least $maxwait/2 + # * we estimate it will take at least $maxwait overall + my $wait_sofar = (time // die $!) - $alloc_start_time; + die "timed out: $wait_sofar, $best->{Start}, $maxwait" + if $wait_sofar > $maxwait/2 + && $wait_sofar + $best->{Start} > $maxwait; + } } if ($fake) { -- 2.39.5