[LON-CAPA-cvs] cvs: loncom /metadata_database parse_activity_log.pl

matthew lon-capa-cvs@mail.lon-capa.org
Thu, 16 Dec 2004 19:29:20 -0000


matthew		Thu Dec 16 14:29:20 2004 EDT

  Modified files:              
    /loncom/metadata_database	parse_activity_log.pl 
  Log:
  Added file locking.
  
  
Index: loncom/metadata_database/parse_activity_log.pl
diff -u loncom/metadata_database/parse_activity_log.pl:1.6 loncom/metadata_database/parse_activity_log.pl:1.7
--- loncom/metadata_database/parse_activity_log.pl:1.6	Thu Dec 16 10:03:29 2004
+++ loncom/metadata_database/parse_activity_log.pl	Thu Dec 16 14:29:20 2004
@@ -2,7 +2,7 @@
 #
 # The LearningOnline Network
 #
-# $Id: parse_activity_log.pl,v 1.6 2004/12/16 15:03:29 matthew Exp $
+# $Id: parse_activity_log.pl,v 1.7 2004/12/16 19:29:20 matthew Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -45,6 +45,8 @@
 use Getopt::Long();
 use IO::File;
 use File::Copy;
+use Fcntl qw(:flock);
+
 #
 # Determine parameters
 my ($help,$course,$domain,$drop,$file,$time_run,$nocleanup,$log,$backup);
@@ -131,13 +133,20 @@
 $error_filename =~ s|[^/]*$|activity.log.errors|;
 $logthis->('Beginning logging '.time);
 
+
+#
+# Wait for a lock on the lockfile to avoid collisions
+my $lockfilename = $sourcefilename.'.lock';
+open(LOCKFILE,'>'.$lockfilename);
+flock(LOCKFILE,LOCK_EX) || die("Unable to lock $lockfilename.  Aborting".$/);
+
 ##
 ## There will only be a $newfilename file if a copy of this program is already
 ## running.
 my $newfilename = $sourcefilename.'.processing';
 if (-e $newfilename) {
     warn "$newfilename exists";
-    $logthis->($newfilename.' exists');
+    $logthis->($newfilename.' exists, so I cannot work on it.');
     exit 2;
 }
 
@@ -153,6 +162,8 @@
     $logthis->('touch was completed');
 }
 
+close(LOCKFILE);
+
 ##
 ## Table definitions
 ##
@@ -328,7 +339,7 @@
         exit 5;
     } elsif ($result > 0) {
         $time_this->();
-        $logthis->('process_courselog returned '.$result.' backup up tables');
+        $logthis->('process_courselog returned '.$result.' backing up tables');
         &backup_tables($gz_sql_filename);
         $time_this->('write backup tables');
     }