Commit 254e3bf3 authored by Leo Gordon's avatar Leo Gordon
Browse files

made it possible for a standaloneJob to provide Runnables with a functional worker_temp_directory()

parent 1ef3199a
......@@ -534,11 +534,35 @@ sub debug {
=cut
sub worker_temp_directory {
my $self = shift;
return undef unless($self->worker);
return $self->worker->worker_process_temp_directory;
my $self = shift @_;
# TODO: simplify $holding_object=$self when -compile_module_once becomes the only option:
my $holding_object = $self->worker ? $self->worker : $self;
unless(defined($holding_object->{'_tmp_dir'}) and (-e $holding_object->{'_tmp_dir'})) {
my $username = $ENV{'USER'};
my $worker_id = $self->worker ? $self->worker->dbID : 'standalone';
$holding_object->{'_tmp_dir'} = "/tmp/worker_${username}.${worker_id}/";
mkdir($holding_object->{'_tmp_dir'}, 0777);
throw("unable to create a writable directory ".$holding_object->{'_tmp_dir'}) unless(-w $holding_object->{'_tmp_dir'});
}
return $holding_object->{'_tmp_dir'};
}
sub cleanup_worker_temp_directory {
my $self = shift @_;
# TODO: simplify $holding_object=$self when -compile_module_once becomes the only option:
my $holding_object = $self->worker ? $self->worker : $self;
if($holding_object->{'_tmp_dir'}) {
my $cmd = "rm -r ". $holding_object->{'_tmp_dir'};
system($cmd);
}
}
#################################################
#
# methods to make porting from RunnableDB easier
......
......@@ -454,21 +454,6 @@ sub toString {
}
sub worker_process_temp_directory {
my $self = shift;
unless(defined($self->{'_tmp_dir'}) and (-e $self->{'_tmp_dir'})) {
#create temp directory to hold fasta databases
my $username = $ENV{'USER'};
my $worker_id = $self->dbID;
$self->{'_tmp_dir'} = "/tmp/worker_${username}.${worker_id}/";
mkdir($self->{'_tmp_dir'}, 0777);
throw("unable to create a writable directory ".$self->{'_tmp_dir'}) unless(-w $self->{'_tmp_dir'});
}
return $self->{'_tmp_dir'};
}
sub cleanup_worker_process_temp_directory {
my $self = shift;
if($self->{'_tmp_dir'}) {
......@@ -589,10 +574,14 @@ sub run {
} while (!$self->cause_of_death); # /Worker's lifespan loop
if($self->perform_cleanup) {
#have runnable cleanup any global/process files/data it may have created
$self->cleanup_worker_process_temp_directory;
}
# have runnable clean up any global/process files/data it may have created
if($self->perform_cleanup) {
if(my $runnable_object = $self->runnable_object()) { # if -compile_module_once is 1, keep _tmp_dir in the Process object:
$runnable_object->cleanup_worker_temp_directory();
} else { # otherwise keep _tmp_dir in the Worker object, so it needs its own cleanup method:
$self->cleanup_worker_process_temp_directory(); # TODO: remove this method when -compile_module_once becomes the only option
}
}
$self->queen->register_worker_death($self);
......
......@@ -10,7 +10,7 @@ use Bio::EnsEMBL::Hive::Utils ('script_usage', 'load_file_or_module', 'parse_cmd
use Data::Dumper;
my ($reg_conf, $help, $debug, $no_write, $flow_into, $input_id);
my ($reg_conf, $help, $debug, $no_write, $no_cleanup, $flow_into, $input_id);
my $module_or_file = shift @ARGV or script_usage();
......@@ -19,6 +19,7 @@ GetOptions(
'debug=i' => \$debug,
'reg_conf|regfile=s' => \$reg_conf,
'no_write|nowrite' => \$no_write,
'no_cleanup' => \$no_cleanup,
'flow_into|flow=s' => \$flow_into,
'input_id=s' => \$input_id,
);
......@@ -64,6 +65,10 @@ $runnable_object->execute_writes( not $no_write );
$runnable_object->life_cycle();
unless($no_cleanup) {
$runnable_object->cleanup_worker_temp_directory();
}
__DATA__
=pod
......
Markdown is supported
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