Skip to content
Snippets Groups Projects
Commit 0af8360e authored by Dan Sheppard's avatar Dan Sheppard
Browse files

Flock-style locking for log files. Needed to automate parts of the Vega

pipeline and run them on the LSF.
parent f2c4ce31
No related branches found
No related tags found
No related merge requests found
......@@ -64,6 +64,7 @@ use POSIX qw(strftime);
use Cwd qw(abs_path);
use DBI;
use Data::Dumper;
use Fcntl qw(:flock SEEK_END);
my $species_c = 1; #counter to be used for each database connection made
......@@ -1191,6 +1192,30 @@ sub log {
return(1);
}
=head2 lock_log
Description : Use flock-style locks to lock log and fastforward to end.
Useful if log is being written to by multiple processes.
=cut
sub lock_log {
my ($self) = @_;
flock($self->{'_log_filehandle'},LOCK_EX) || die "Cannot lock log";
seek($self->{'_log_filehandle'},0,SEEK_END) || die "Cannot seek log";
}
=head2 unlock_log
Description : Unlock log previously locked by lock_log.
=cut
sub unlock_log {
my ($self) = @_;
# flush is implicit in flock
flock($self->{'_log_filehandle'},LOCK_UN) || die "Cannot unlock log";
}
=head2 log_warning
Arg[1] : String $txt - the warning text to log
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment