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