From edbb1cb3ce0c8bb83d0ebff085d25e758d46998b Mon Sep 17 00:00:00 2001 From: =?utf8?q?Jan=20Kr=C3=BCger?= Date: Fri, 5 Nov 2010 04:10:40 +0100 Subject: [PATCH] jobd: properly skip unnecessary jobs MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Previously, jobs were skipped by having them execute /bin/false. That is not only a waste of resources but can also cause annoying race conditions if false exits more quickly than we can associate it with its PID. Therefore, add a proper system for skipping jobs altogether and include skipped jobs in progress output. Signed-off-by: Jan Krüger --- jobd/jobd.pl | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/jobd/jobd.pl b/jobd/jobd.pl index f0f55ad..2fd6eb6 100755 --- a/jobd/jobd.pl +++ b/jobd/jobd.pl @@ -87,6 +87,7 @@ my @running; my $perpetual = 1; my $locked = 0; my $jobs_executed; +my $jobs_skipped; my @jobs_killed; sub handle_softexit { @@ -125,6 +126,7 @@ sub handle_childgone { sub queue_job { my %opts = @_; $opts{'queued_at'} = time; + $opts{'dont_run'} = 0; push @queue, \%opts; } @@ -133,6 +135,11 @@ sub run_job { push @running, $job; $job->{'command'}->($job); + if ($job->{'dont_run'}) { + pop @running; + $jobs_skipped++; + return; + } } sub _job_name { @@ -168,7 +175,7 @@ sub exec_job_command { sub job_skip { my $job = shift; - exec_job_command($job, ['/bin/false']); + $job->{'dont_run'} = 1; } sub reap_hanging_jobs { @@ -198,6 +205,7 @@ sub reap_finished_jobs { sub run_queue { my $last_progress = time; $jobs_executed = 0; + $jobs_skipped = 0; @jobs_killed = (); unless ($quiet) { printf STDERR "--- Processing %d queued jobs\n", scalar(@queue); @@ -212,7 +220,7 @@ sub run_queue { if (@running >= $max_par) { sleep 10; unless (($quiet && !$progress) || (time - $last_progress) < 60) { - printf STDERR "STATUS: %d queued, %d running, %d finished, %d killed\n", scalar(@queue), scalar(@running), $jobs_executed, scalar(@jobs_killed); + printf STDERR "STATUS: %d queued, %d running, %d finished, %d skipped, %d killed\n", scalar(@queue), scalar(@running), $jobs_executed, $jobs_skipped, scalar(@jobs_killed); if (@running) { my @run_status; for (@running) { @@ -228,7 +236,7 @@ sub run_queue { run_job(shift(@queue)) if @queue; } unless ($quiet) { - printf STDERR "--- Queue processed. %d jobs executed, %d killed due to timeouts. Now restarting.\n", $jobs_executed, scalar(@jobs_killed); + printf STDERR "--- Queue processed. %d jobs executed, %d skipped, %d killed. Now restarting.\n", $jobs_executed, $jobs_skipped, scalar(@jobs_killed); } } -- 2.11.4.GIT