From e965c53d85483b17a549a30e42ce195d710c4573 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Jan=20Kr=C3=BCger?= Date: Fri, 5 Nov 2010 18:41:48 +0100 Subject: [PATCH] jobd: check update/gc timestamps before ever running update.sh/gc.sh MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit This should make for another nice speedup since we don't need to wait for the update.sh/gc.sh processes any longer. Signed-off-by: Jan Krüger --- jobd/jobd.pl | 31 +++++++++++++++++++++++++------ 1 file changed, 25 insertions(+), 6 deletions(-) diff --git a/jobd/jobd.pl b/jobd/jobd.pl index 9dda282..3025bd6 100755 --- a/jobd/jobd.pl +++ b/jobd/jobd.pl @@ -31,8 +31,12 @@ sub update_project { my $job = shift; my $p = $job->{'project'}; check_project_exists($job) || return; - (-e "$Girocco::Config::reporoot/$p.git/.nofetch") && do { + if (-e get_project_path($p).".nofetch") { job_skip($job); + return setup_gc($job); + } + if (my $ts = is_operation_uptodate($p, 'lastrefresh', $Girocco::Config::min_mirror_interval)) { + job_skip($job, "not needed right now, last run at $ts"); setup_gc($job); return; }; @@ -43,6 +47,10 @@ sub gc_project { my $job = shift; my $p = $job->{'project'}; check_project_exists($job) || return; + if (my $ts = is_operation_uptodate($p, 'lastgc', $Girocco::Config::min_gc_interval)) { + job_skip($job, "not needed right now, last run at $ts"); + return; + } exec_job_command($job, ["$Girocco::Config::basedir/jobd/gc.sh", $p], $quiet); } @@ -59,15 +67,25 @@ sub setup_gc { sub check_project_exists { my $job = shift; my $p = $job->{'project'}; - if (!-d "$Girocco::Config::reporoot/$p.git") { - error("Warning: skipping non-existent project: $job->{project}") - unless $quiet; - job_skip(); + if (!-d get_project_path($p)) { + job_skip($job, "non-existent project"); return 0; } 1; } +sub get_project_path { + "$Girocco::Config::reporoot/".shift().".git/"; +} + +sub is_operation_uptodate { + my ($project, $which, $threshold) = @_; + my $path = get_project_path($project); + my $timestamp = `GIT_DIR="$path" $Girocco::Config::git_bin config "gitweb.$which"`; + my $unix_ts = `date +%s -d "$timestamp"`; + (time - $unix_ts) <= $threshold ? $timestamp : undef; +} + sub queue_one { my $project = shift; queue_job( @@ -177,8 +195,9 @@ sub exec_job_command { } sub job_skip { - my $job = shift; + my ($job, $msg) = @_; $job->{'dont_run'} = 1; + error(_job_name($job) ." Skipping job: $msg") unless $quiet || !$msg; } sub reap_hanging_jobs { -- 2.11.4.GIT