Bio-BioVeL

 view release on metacpan or  search on metacpan

lib/Bio/BioVeL/AsynchronousService.pm  view on Meta::CPAN

				$self->status( ERROR );
			}
			else {
				$log->info("ModPerl::Util::exit was trapped, assume we are done");
				$self->status( DONE );
			}
		}
		else {
			$log->info("launched $self successfully");
			$self->status( RUNNING );
		}		
	}
	return $self;
}

=item launch

The concrete child class needs to implement the launch() method, which presumably
will fork off a process, e.g. using system("command &"), such that it will be able
to keep track of its status, e.g. by knowing the PID of the child processes.

=cut

sub launch { 
	die "The launch() method needs to be implemented by the concrete child class\n" 
}

=item launch_wrapper

Wraps the service launch() inside a fork() to keep track of the PID.

=cut

sub launch_wrapper {
	my $self = shift;
	my $log  = $self->logger;
	my $pid  = fork();
	if ( $pid == 0 ) {
		
		# we're in the child process
		$log->info("launching the child process");
		$self->launch;
		exit(0);
	}
	else {
	
		# we're in the parent
		$log->info("launched service job with PID $pid");
		$self->pid($pid);
	}
}

=item update 

The concrete child class needs to implement the update() method, which will check on
the process that was launched by launch(), and will update the status, e.g. from RUNNING
to DONE or ERROR.

=cut

sub update { 
	my $self   = shift;
	my $log    = $self->logger;
	my $status = DONE;
	if ( my $pid = $self->pid ) {
		my $timestamp = $self->timestamp;
		my $pt = Proc::ProcessTable->new;
		PROC: for my $proc ( @{ $pt->table } ) {
			if ( $proc->pid == $pid ) {
				if ( abs( $timestamp - $proc->start ) < 2 ) {
					$log->info("still running: ".$proc->cmndline);
					$status = RUNNING;
					last PROC;
				}
			}
		}
	}
	$self->status($status);
}

=item jobid

The unique ID of the service job.

=cut

sub jobid {
	my $self = shift;
	$self->{'jobid'} = shift if @_;
	return $self->{'jobid'};
}

=item pid

The process ID of the service job.

=cut

sub pid {
	my $self = shift;
	$self->{'pid'} = shift if @_;
	return $self->{'pid'};
}

=item timestamp

The launch timestamp of the job.

=cut

sub timestamp { 
	my $self = shift;
	$self->{'timestamp'} = shift if @_;
	return $self->{'timestamp'};
}

=item lasterr

The last error string that occurred.

=cut



( run in 1.731 second using v1.01-cache-2.11-cpan-9581c071862 )