Commit a5ac7ca0 authored by Matthieu Muffato's avatar Matthieu Muffato
Browse files

New option to change the base directory in which workers will create their own temp directories

parent df13b84b
......@@ -101,7 +101,7 @@ package Bio::EnsEMBL::Hive::Process;
use strict;
use warnings;
use File::Path qw(remove_tree);
use File::Path qw(make_path remove_tree);
use JSON;
use Scalar::Util qw(looks_like_number);
use Time::HiRes qw(time);
......@@ -679,7 +679,7 @@ sub worker_temp_directory {
unless(defined($self->{'_tmp_dir'}) and (-e $self->{'_tmp_dir'})) {
$self->{'_tmp_dir'} = $self->worker_temp_directory_name();
mkdir($self->{'_tmp_dir'}, 0777);
make_path( $self->{'_tmp_dir'}, { mode => 0777 } );
throw("unable to create a writable directory ".$self->{'_tmp_dir'}) unless(-w $self->{'_tmp_dir'});
}
return $self->{'_tmp_dir'};
......
......@@ -128,10 +128,10 @@ sub create_new_worker {
my %flags = @_;
my ($preregistered, $resource_class_id, $resource_class_name, $beekeeper_id,
$no_write, $debug, $worker_log_dir, $hive_log_dir, $job_limit, $life_span, $no_cleanup, $retry_throwing_jobs, $can_respecialize,
$no_write, $debug, $worker_base_temp_dir, $worker_log_dir, $hive_log_dir, $job_limit, $life_span, $no_cleanup, $retry_throwing_jobs, $can_respecialize,
$worker_delay_startup_seconds, $worker_crash_on_startup_prob, $config_files)
= @flags{qw(-preregistered -resource_class_id -resource_class_name -beekeeper_id
-no_write -debug -worker_log_dir -hive_log_dir -job_limit -life_span -no_cleanup -retry_throwing_jobs -can_respecialize
-no_write -debug -worker_base_temp_dir -worker_log_dir -hive_log_dir -job_limit -life_span -no_cleanup -retry_throwing_jobs -can_respecialize
-worker_delay_startup_seconds -worker_crash_on_startup_prob -config_files)};
sleep( $worker_delay_startup_seconds // 0 ); # NB: undefined parameter would have caused eternal sleep!
......@@ -222,6 +222,7 @@ sub create_new_worker {
}
$worker->set_log_directory_name($hive_log_dir, $worker_log_dir);
$worker->set_temp_directory_name( $worker_base_temp_dir );
$worker->init;
......
......@@ -58,6 +58,7 @@ sub runWorker {
-life_span => $life_options->{'life_span'},
-no_cleanup => $execution_options->{'no_cleanup'},
-no_write => $execution_options->{'no_write'},
-worker_base_temp_dir => $execution_options->{'worker_base_temp_dir'},
-worker_log_dir => $execution_options->{'worker_log_dir'},
-hive_log_dir => $execution_options->{'hive_log_dir'},
-retry_throwing_jobs => $life_options->{'retry_throwing_jobs'},
......
......@@ -243,6 +243,23 @@ sub log_dir {
}
=head2 temp_directory_name
Arg [1] : (optional) string directory path
Title : temp_directory_name
Usage : $worker_tmp_dir = $self->temp_directory_name;
$self->temp_directory_name($worker_tmp_dir);
Description: Storable getter/setter attribute for the directory where jobs can store temporary data.
Returntype : string
=cut
sub temp_directory_name {
my $self = shift;
$self->{'_tmp_dir'} = shift if(@_);
return $self->{'_tmp_dir'};
}
## Non-Storable attributes:
......@@ -906,14 +923,28 @@ sub set_log_directory_name {
}
sub temp_directory_name {
my $self = shift @_;
=head2 set_temp_directory_name
Title : set_temp_directory_name
Description : Generates and sets the name of a temporary directory suitable for this worker.
It will be under the base directory requested by $base_temp_dir, or /tmp
otherwise, and includes worker attributes to make the path unique.
=cut
sub set_temp_directory_name {
my ($self, $base_temp_dir) = @_;
$base_temp_dir //= '/tmp';
my $temp_directory_name;
if ($self->adaptor) {
return sprintf('/tmp/worker_%s_%s.%s/', $self->meadow_user, $self->hive_pipeline->hive_pipeline_name, $self->dbID);
$temp_directory_name = sprintf('%s/worker_%s_%s.%s/', $base_temp_dir, $self->meadow_user, $self->hive_pipeline->hive_pipeline_name, $self->dbID);
} else {
return sprintf('/tmp/worker_%s.standalone.%s/', $self->meadow_user, $self->process_id);
$temp_directory_name = sprintf('%s/worker_%s.standalone.%s/', $base_temp_dir, $self->meadow_user, $self->process_id);
}
$self->temp_directory_name( $temp_directory_name );
}
......
......@@ -27,7 +27,7 @@ main();
sub main {
my ($url, $reg_conf, $reg_type, $reg_alias, $nosqlvc); # Connection parameters
my ($preregistered, $resource_class_id, $resource_class_name, $analyses_pattern, $analysis_id, $logic_name, $job_id, $force, $beekeeper_id); # Task specification parameters
my ($job_limit, $life_span, $no_cleanup, $no_write, $worker_cur_dir, $hive_log_dir, $worker_log_dir, $retry_throwing_jobs, $can_respecialize, # Worker control parameters
my ($job_limit, $life_span, $no_cleanup, $no_write, $worker_cur_dir, $hive_log_dir, $worker_log_dir, $worker_base_temp_dir, $retry_throwing_jobs, $can_respecialize, # Worker control parameters
$worker_delay_startup_seconds, $worker_crash_on_startup_prob, $config_files);
my ($help, $report_versions, $debug);
......@@ -67,6 +67,7 @@ sub main {
'worker_cur_dir|cwd=s' => \$worker_cur_dir,
'hive_log_dir|hive_output_dir=s' => \$hive_log_dir, # keep compatibility with the old name
'worker_log_dir|worker_output_dir=s' => \$worker_log_dir, # will take precedence over hive_log_dir if set
'worker_base_temp_dir=s' => \$worker_base_temp_dir,
'retry_throwing_jobs!' => \$retry_throwing_jobs,
'can_respecialize|can_respecialise!' => \$can_respecialize,
'worker_delay_startup_seconds=i' => \$worker_delay_startup_seconds,
......@@ -143,6 +144,7 @@ sub main {
config_files => $config_files,
no_cleanup => $no_cleanup,
no_write => $no_write,
worker_base_temp_dir=> $worker_base_temp_dir,
worker_log_dir => $worker_log_dir,
hive_log_dir => $hive_log_dir,
debug => $debug,
......@@ -273,6 +275,11 @@ don't perform temp directory cleanup when the Worker exits
don't write_output or auto_dataflow input_job
=item --worker_base_temp_dir <path>
The base directory that this worker will use for temporary operations. This overrides the default set
in the JSON config file and in the code (/tmp)
=item --hive_log_dir <path>
directory where stdout/stderr of the whole eHive of workers is redirected
......
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