From: Martin Mares Date: Mon, 31 Oct 2011 10:37:17 +0000 (+0100) Subject: Keep history of completed jobs X-Git-Tag: v3.0~56 X-Git-Url: http://mj.ucw.cz/gitweb/?a=commitdiff_plain;h=07d043c624f4450e46acc424c553bb85bbecca5f;p=bex.git Keep history of completed jobs --- diff --git a/NOTES b/NOTES index 567f305..71d7fe9 100644 --- a/NOTES +++ b/NOTES @@ -12,6 +12,9 @@ /jobs/.job All jobs issued on this queue, including those which are no longer queued for any machine +/history// Successfully completed jobs (their .job, .stat and .log files) + are moved here if the keep_history config switch is set. + /log Log of actions on this queue. Lines look this way: YYYY-MM-DD HH:MM:SS [] and correspond to "Status" and "Message" diff --git a/TODO b/TODO index 6d96283..6b146e7 100644 --- a/TODO +++ b/TODO @@ -10,3 +10,4 @@ - ssh options - Detector of orphans (unused queue dirs, jobs on non-existent machines, non-queued jobs) - job failed => give a more explanatory message +- configurable hostnames of hosts diff --git a/lib/BEX/Config.pm b/lib/BEX/Config.pm index 9834468..a364b2c 100644 --- a/lib/BEX/Config.pm +++ b/lib/BEX/Config.pm @@ -20,6 +20,9 @@ our $job_prolog = 'prolog'; # A file whose contents should be appended to the job our $job_epilog = 'epilog'; +# Keep history of successfully completed jobs +our $keep_history = 1; + # Various utility functions sub parse_machine_list(@); diff --git a/lib/BEX/Queue.pm b/lib/BEX/Queue.pm index 00bb6cb..712ecff 100644 --- a/lib/BEX/Queue.pm +++ b/lib/BEX/Queue.pm @@ -7,6 +7,7 @@ use warnings; package BEX::Queue; use IO::File; +use File::Path; use POSIX (); sub new($;$) { @@ -102,10 +103,23 @@ sub scan($$) { sub remove($$) { my ($queue, $machine, $jid) = @_; - unlink $queue->queue_file($machine, $jid); - unlink $queue->status_file($machine, $jid); + if ($BEX::Config::keep_history) { + my $s = $queue->{'Name'} . '/hosts/' . $machine; + my $d = $queue->{'Name'} . '/history/' . $machine; + File::Path::make_path($d); + for my $suff ('job', 'stat', 'log') { + my $src = "$s/$jid.$suff"; + my $dst = "$d/$jid.$suff"; + if (-f $src) { + rename $src, $dst or die "Cannot rename $src to $dst: $!"; + } + } + } else { + unlink $queue->queue_file($machine, $jid); + unlink $queue->status_file($machine, $jid); + unlink $queue->log_file($machine, $jid); + } unlink $queue->temp_file($machine, $jid); - unlink $queue->log_file($machine, $jid); } sub job_metadata($$) {