[pve-devel] [PATCH manager 1/3] pvescheduler: simplify code for sleep time calculation

Fabian Ebner f.ebner at proxmox.com
Thu Nov 11 16:17:43 CET 2021


Signed-off-by: Fabian Ebner <f.ebner at proxmox.com>
---
 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
-- 
2.30.2






More information about the pve-devel mailing list