]> mj.ucw.cz Git - bex.git/commitdiff
Keep history of completed jobs
authorMartin Mares <mj@ucw.cz>
Mon, 31 Oct 2011 10:37:17 +0000 (11:37 +0100)
committerMartin Mares <mj@ucw.cz>
Mon, 31 Oct 2011 10:37:17 +0000 (11:37 +0100)
NOTES
TODO
lib/BEX/Config.pm
lib/BEX/Queue.pm

diff --git a/NOTES b/NOTES
index 567f3059f816a166360639dae2af3369630f647a..71d7fe92ee9d3cb649cdf368a5b1fac2ced73ce5 100644 (file)
--- a/NOTES
+++ b/NOTES
@@ -12,6 +12,9 @@
 <queue>/jobs/<job-id>.job      All jobs issued on this queue, including those which
                                are no longer queued for any machine
 
+<queue>/history/<hostname>/    Successfully completed jobs (their .job, .stat and .log files)
+                               are moved here if the keep_history config switch is set.
+
 <queue>/log                    Log of actions on this queue. Lines look this way:
                                YYYY-MM-DD HH:MM:SS <host> <job-id> <status> [<msg>]
                                <status> and <msg> correspond to "Status" and "Message"
diff --git a/TODO b/TODO
index 6d962830f23a4d2c534f737c28c66343779315fb..6b146e7b1551f4ddca487625a52640b21f33fb29 100644 (file)
--- 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
index 98344685753445c5450ad27e466247264c4e4165..a364b2cd540727fb9b035fc7c90922936486d63e 100644 (file)
@@ -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(@);
index 00bb6cb2acff6d38e46d3cc6a16cdbef52f0125e..712ecff20a6e928441cfaef05c1a16191fcf31c5 100644 (file)
@@ -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($$) {