Commit f486d5ba authored by Leo Gordon's avatar Leo Gordon
Browse files

an attempt to allow multiple users' beekeepers to keep one hive (needs more testing)

parent 0760257c
......@@ -34,12 +34,18 @@ sub meadow_options { # general options that different Meadows can plug into t
return $self->{'_meadow_options'} || '';
}
sub job_name_prefix {
my $self = shift @_;
return ($self->pipeline_name() ? $self->pipeline_name().'-' : '') . 'Hive';
}
sub generate_job_name {
my ($self, $worker_count, $iteration, $rc_id) = @_;
$rc_id ||= 0;
return ($self->pipeline_name() ? $self->pipeline_name().'-' : '')
."Hive${rc_id}_${iteration}"
return $self->job_name_prefix()
."${rc_id}_${iteration}"
. (($worker_count > 1) ? "[1-${worker_count}]" : '');
}
......@@ -49,7 +55,7 @@ sub responsible_for_worker {
return $worker->beekeeper() eq $self->type();
}
sub check_worker_is_alive {
sub check_worker_is_alive_and_mine {
my ($self, $worker) = @_;
die "Please use a derived method";
......
......@@ -29,7 +29,7 @@ sub responsible_for_worker {
return ( $self->SUPER::responsible_for_worker($worker) && ($worker->host eq hostname()) );
}
sub status_of_all_my_workers { # returns a hashref
sub status_of_all_our_workers { # returns a hashref
my ($self) = @_;
my $cmd = 'ps x -o state,pid,command -w -w | grep runWorker.pl | grep -v "grep runWorker.pl" ';
......@@ -53,19 +53,21 @@ sub status_of_all_my_workers { # returns a hashref
return \%status_hash;
}
sub check_worker_is_alive {
sub check_worker_is_alive_and_mine {
my ($self, $worker) = @_;
my $cmd = 'ps '. $worker->process_id . ' 2>&1 | grep ' . $worker->process_id;
my $is_alive = qx/$cmd/;
return $is_alive;
my $wpid = $worker->process_id();
my $cmd = qq{ps x | grep $wpid | grep -v 'grep $wpid'};
my $is_alive_and_mine = qx/$cmd/;
return $is_alive_and_mine;
}
sub kill_worker {
my ($self, $worker) = @_;
if( $self->responsible_for_worker($worker) ) {
if($self->check_worker_is_alive($worker)) {
if($self->check_worker_is_alive_and_mine($worker)) {
my $cmd = 'kill -9 '.$worker->process_id();
system($cmd);
} else {
......
......@@ -26,13 +26,8 @@ sub get_current_worker_process_id {
sub count_pending_workers {
my ($self) = @_;
my $cmd = "bjobs -w ";
if(my $pipeline_name = $self->pipeline_name()) {
$cmd .= " | grep '${pipeline_name}-Hive'";
} else {
$cmd .= " | grep Hive";
}
$cmd .= " | grep -c PEND";
my $jnp = $self->job_name_prefix();
my $cmd = qq{bjobs -w -J '${jnp}*' -u all | grep -c PEND};
my $pend_count = qx/$cmd/;
chomp($pend_count);
......@@ -40,15 +35,11 @@ sub count_pending_workers {
return $pend_count;
}
sub status_of_all_my_workers { # returns a hashref
sub status_of_all_our_workers { # returns a hashref
my ($self) = @_;
my $cmd = 'bjobs -w 2>&1 | grep -v "No unfinished job found" | grep -v JOBID | grep -v DONE | grep -v EXIT';
if(my $pipeline_name = $self->pipeline_name()) {
$cmd .= " | grep '${pipeline_name}-Hive'";
} else {
$cmd .= " | grep Hive";
}
my $jnp = $self->job_name_prefix();
my $cmd = qq{bjobs -w -J '${jnp}*' -u all 2>&1 | grep -v 'No unfinished job found' | grep -v JOBID | grep -v DONE | grep -v EXIT};
my %status_hash = ();
foreach my $line (`$cmd`) {
......@@ -64,18 +55,21 @@ sub status_of_all_my_workers { # returns a hashref
return \%status_hash;
}
sub check_worker_is_alive {
sub check_worker_is_alive_and_mine {
my ($self, $worker) = @_;
my $cmd = 'bjobs '. $worker->process_id . ' 2>&1 | grep -v "not found" | grep -v JOBID | grep -v EXIT';
my $is_alive = qx/$cmd/;
return $is_alive;
my $wpid = $worker->process_id();
my $this_user = $ENV{'USER'};
my $cmd = qq{bjobs $wpid -u $this_user 2>&1 | grep -v 'not found' | grep -v JOBID | grep -v EXIT};
my $is_alive_and_mine = qx/$cmd/;
return $is_alive_and_mine;
}
sub kill_worker {
my ($self, $worker) = @_;
if($self->check_worker_is_alive($worker)) {
if($self->check_worker_is_alive_and_mine($worker)) {
my $cmd = 'bkill '.$worker->process_id();
system($cmd);
} else {
......
......@@ -201,7 +201,7 @@ sub register_worker_death {
sub check_for_dead_workers {
my ($self, $meadow, $check_buried_in_haste) = @_;
my $worker_status_hash = $meadow->status_of_all_my_workers();
my $worker_status_hash = $meadow->status_of_all_our_workers();
my %worker_status_summary = ();
my $queen_worker_list = $self->fetch_overdue_workers(0);
......
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