--- loncom/metadata_database/parse_activity_log.pl 2004/12/16 15:03:29 1.6 +++ loncom/metadata_database/parse_activity_log.pl 2004/12/16 19:29:20 1.7 @@ -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 Time::HiRes(); 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 = $sourcefilename; $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 @@ if (-e $sourcefilename) { $logthis->('touch was completed'); } +close(LOCKFILE); + ## ## Table definitions ## @@ -328,7 +339,7 @@ if (-s $newfilename) { 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'); }