| Helios documentation | Contained in the Helios distribution. |
Helios::TestService - Helios::Service subclass for testing purposes
You can use Helios::TestService to test the functionality of your Helios collective.
Start a helios.pl daemon to service Helios::TestService jobs by issuing:
helios.pl Helios::TestService
at a command prompt.
Submit a job, either from code you're trying to test, or through the Helios::Panoptes Submit Job page.
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.
These are disabled as we don't normally want to retry test jobs.
The run() method just logs the arguments passed to the job.
Andrew Johnson, <ajohnson at ittoolbox dotcom>
Copyright (C) 2008 by CEB Toolbox, Inc.
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.8.0 or, at your option, any later version of Perl 5 you may have available.
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__