Commit 321e4b53 authored by Matthieu Muffato's avatar Matthieu Muffato
Browse files

Clearer flags in register_worker_death()

"self-burial" had two meanings:
 - should we release the undone jobs ?
 - should we update the last_check_in field in the worker table ?
The former can simply be found by checking whether the worker already has a
role attached to it.
The latter is only set when a worker registers its own death, and is not set
by the GarbageCollector.
parent df4a98bb
......@@ -60,7 +60,7 @@ sub object_class {
sub finalize_role {
my ($self, $role, $self_burial) = @_;
my ($self, $role, $release_undone_jobs) = @_;
my $role_id = $role->dbID;
my $when_finished = $role->when_finished ? "'".$role->when_finished."'" : 'CURRENT_TIMESTAMP';
......@@ -73,7 +73,7 @@ sub finalize_role {
$self->db->get_AnalysisStatsAdaptor->decrease_running_workers( $role->analysis_id );
}
unless( $self_burial ) {
if( $release_undone_jobs ) {
$self->db->get_AnalysisJobAdaptor->release_undone_jobs_from_role( $role );
}
......
......@@ -286,7 +286,7 @@ sub specialize_worker {
sub register_worker_death {
my ($self, $worker, $self_burial) = @_;
my ($self, $worker, $update_last_check_in) = @_;
my $worker_id = $worker->dbID;
my $work_done = $worker->work_done;
......@@ -294,19 +294,22 @@ sub register_worker_death {
my $worker_died = $worker->died;
my $current_role = $worker->current_role;
my $release_undone_jobs = 0;
unless( $current_role ) {
$worker->current_role( $current_role = $self->db->get_RoleAdaptor->fetch_last_unfinished_by_worker_id( $worker_id ) );
# $current_role can be undef if the cause_of_death is NO_ROLE
$release_undone_jobs = 1 if $current_role;
}
if( $current_role and !$current_role->when_finished() ) {
$current_role->worker($worker); # So that release_undone_jobs_from_role() has the correct cause_of_death and work_done
$current_role->when_finished( $worker_died );
$self->db->get_RoleAdaptor->finalize_role( $current_role, $self_burial );
$self->db->get_RoleAdaptor->finalize_role( $current_role, $release_undone_jobs );
}
my $sql = "UPDATE worker SET status='DEAD', work_done='$work_done', cause_of_death='$cause_of_death'"
. ( $self_burial ? ', last_check_in=CURRENT_TIMESTAMP ' : '' )
. ( $update_last_check_in ? ', last_check_in=CURRENT_TIMESTAMP ' : '' )
. ( $worker_died ? ", died='$worker_died'" : ', died=CURRENT_TIMESTAMP' )
. " WHERE worker_id='$worker_id' ";
......
......@@ -539,7 +539,7 @@ sub run {
if( $cod =~ /^(NO_WORK|HIVE_OVERLOAD)$/ and $self->can_respecialize and (!$specialization_arghash->{'-analyses_pattern'} or $specialization_arghash->{'-analyses_pattern'}!~/^\w+$/) ) {
my $old_role = $self->current_role;
$self->adaptor->db->get_RoleAdaptor->finalize_role( $old_role, 1 );
$self->adaptor->db->get_RoleAdaptor->finalize_role( $old_role, 0 );
$self->current_role( undef );
$self->cause_of_death(undef);
$self->specialize_and_compile_wrapper( $specialization_arghash, $old_role->analysis );
......@@ -555,8 +555,8 @@ sub run {
}
# The second arguments ("self_burial") controls whether we need to
# release the current (unfinished) batch
$self->adaptor->register_worker_death($self, ($self->cause_of_death eq 'CONTAMINATED' ? 0 : 1));
# update the "last_check_in" date in the worker table
$self->adaptor->register_worker_death($self, 1);
if($self->debug) {
$self->worker_say( 'AnalysisStats : '.$self->current_role->analysis->stats->toString ) if( $self->current_role );
......
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