Helios::TestService - Helios::Service subclass for testing purposes


Helios documentation Contained in the Helios distribution.

Index


Code Index:

NAME

Top

Helios::TestService - Helios::Service subclass for testing purposes

DESCRIPTION

Top

You can use Helios::TestService to test the functionality of your Helios collective.

1.

Start a helios.pl daemon to service Helios::TestService jobs by issuing:

 helios.pl Helios::TestService

at a command prompt.

2.

Submit a job, either from code you're trying to test, or through the Helios::Panoptes Submit Job page.

3.

Helios should run the test job. The job arguments will be parsed and logged as entries in the Helios log. If argument parsing fails, there will be an error in the log instead.

METHODS

Top

max_retries()

retry_delay()

These are disabled as we don't normally want to retry test jobs.

run()

The run() method just logs the arguments passed to the job.

SEE ALSO

Top

Helios::Service

AUTHOR

Top

Andrew Johnson, <ajohnson at ittoolbox dotcom>

COPYRIGHT AND LICENSE

Top

WARRANTY

Top

This software comes with no warranty of any kind.


Helios documentation Contained in the Helios distribution.
package Helios::TestService;

use 5.008000;
use base qw( Helios::Service );
use strict;
use warnings;

use Error qw(:try);

use Helios::Error;			# pulls in all Helios::Error::* exception types
use Helios::Job;
use Helios::LogEntry::Levels qw(:all);

our $VERSION = '2.20';	# necessary for packaging purposes

#sub max_retries { return 2; }
#sub retry_delay { return 60; }

sub run {
	my $self = shift;
	my $job = shift;
	my $config = $self->getConfig();
	my $args = $job->getArgs();

	try {
		if ($self->debug) {
			print "--CONFIG PARAMS--\n";
			foreach (keys %$config) {
				print $_,'=',$config->{$_},"\n";
			}
		}

		if ($self->debug) { print "--JOB ARGUMENTS--\n"; }
		foreach my $arg (sort keys %$args) {
			if ($self->debug) { print uc($arg),'=',$args->{$arg},"|\n"; }
			$self->logMsg($job, LOG_DEBUG, "PARAM: $arg VALUE: ".$args->{$arg});
		}
		if ( defined($args->{failure}) ) {
			throw Helios::Error::Fatal("Artificially throwing error here");
		}
		# if your job completes successfully, you need to mark it was completed
		$self->completedJob($job);

	} catch Helios::Error::Warning with {
		# you can throw this in your "WORK" section to denote your job completed, but had warnings
		my $e = shift;
		$self->logMsg($job, LOG_WARNING, "Class $self WARNING: ".$e->text);
		$self->completedJob($job);
	} catch Helios::Error::Fatal with {
		# you can throw this in your "WORK" section to denote a job that failed
		# (it will be retried if you have defined max_retries() and this job hasn't been retried that many times)
		my $e = shift;
		$self->logMsg($job, LOG_ERR, "Class $self FAILED: ".$e->text);
		$self->failedJob($job, $e->text."(Class $self)",835);
	} otherwise {
		# "otherwise" catches unexpected errors that you perhaps didn't throw
		# usually you can mark the jobs as failed and have them retried
		my $e = shift;
		$self->logMsg($job, LOG_ERR, "Class $self FAILED with unexpected error: ".$e->text);
		$self->failedJob($job, $e->text."(Class $self)");
	};

}




1;
__END__