From db101be037a8ad0d4b6db20367e61d1d3591f821 Mon Sep 17 00:00:00 2001 From: Fabian Ebner Date: Thu, 11 Nov 2021 16:17:43 +0100 Subject: [PATCH] pvescheduler: simplify code for sleep time calculation Signed-off-by: Fabian Ebner --- PVE/Service/pvescheduler.pm | 22 ++++------------------ 1 file changed, 4 insertions(+), 18 deletions(-) diff --git a/PVE/Service/pvescheduler.pm b/PVE/Service/pvescheduler.pm index a8d548fb..86891827 100755 --- a/PVE/Service/pvescheduler.pm +++ b/PVE/Service/pvescheduler.pm @@ -25,20 +25,6 @@ my $finish_jobs = sub { } }; -my $get_sleep_time = sub { - my ($calculate_offset) = @_; - my $time = 60; - - if ($calculate_offset) { - # try to run near minute boundaries, makes more sense to the user as he - # configures jobs with minute precision - my ($current_seconds) = localtime; - $time = (60 - $current_seconds) if (60 - $current_seconds >= 5); - } - - return $time; -}; - sub run { my ($self) = @_; @@ -84,12 +70,12 @@ sub run { $run_jobs->(); - my $sleep_time; + my $sleep_time = 60; if ($count >= 1000) { - $sleep_time = $get_sleep_time->(1); + # Job schedule has minute precision, so try running near the minute boundary. + my ($current_seconds) = localtime; + $sleep_time = (60 - $current_seconds) if (60 - $current_seconds >= 5); $count = 0; - } else { - $sleep_time = $get_sleep_time->(0); } my $slept = 0; # SIGCHLD interrupts sleep, so we need to keep track