The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

HeliosX::Job::JSON - Helios::Job subclass using JSON to specify job arguments

SYNOPSIS

 # in your Helios::Service class
 package MyService;
 use parent 'Helios::Service';
 use HeliosX::Job::JSON;
 
 sub JobClass { 'HeliosX::Job::JSON' }
 
 sub run {
        ... run code here ... 
 }
 
 1;
 
 # in your job submission code, use HeliosX::Job::JSON just like Helios::Job
 my $config = Helios::Config->parseConfig();
 my $arg_json = qq/{ "args" : { "arg1": "value1", "arg2": "string2" } }/; 
 my $job = HeliosX::Job::JSON->new();
 $job->setConfig($config);
 $job->setJobType('MyService');
 $job->setArgString($arg_json);
 my $jobid = $job->submit();
 
 # or use the included helios_job_submit_json command 
 helios_job_submit_json MyService '{ "args" : { "arg1": "value1", "arg2": "string2" } }'

DESCRIPTION

HeliosX::Job::JSON is a Helios::Job subclass allowing you to specify Helios job arguments in JSON format instead of Helios's default XML format. If parts of your application or system use the JSON data format, or your Helios job arguments are difficult to express in XML, you can change your Helios service to use HeliosX::Job::JSON to specify your job arguments in JSON.

JSON JOB ARGUMENT FORMAT

To specify a Helios job's arguments in JSON, use the following JSON object as an example:

 {
     "jobtype" : "Helios::TestService",
     "args": {
         "arg1"          : "value1",
         "arg2"          : "value2",
         "original_file" : "photo.jpg",
         "size"          : "125x125"
     }
 }

Your JSON object will define a "jobtype" string and an "args" object. The name and value pairs of the args object will become the job's argument hash.

The jobtype value is optional if you specify a jobtype another way i.e. using the --jobtype option with helios_job_submit_json or using HeliosX::Job::JSON's setJobType() method.

NOTE ABOUT METAJOBS

HeliosX::Job::JSON does not yet support Helios metajobs. Specifying metajob arguments in JSON may be supported in a future release.

METHODS

parseArgs()

HeliosX::Job::JSON's parseArgs() method is much simpler than Helios::Job's because JSON's object format is very close to Perl's concept of a hash.

parseArgString($json_string)

The parseArgString() method does the actual parsing of the JSON object string into the Perl hash using JSON::Tiny.

submit()

HeliosX::Job::JSON's submit() method is actually a shell around Helios::Job's submit() to allow specifying the jobtype via the JSON object instead of requiring a separate call to setJobType(). If the jobtype wasn't explicitly specified and submit() cannot determine the jobtype from the JSON object, it will throw a HeliosX::Job::JSON::Error exception.

SEE ALSO

Helios, Helios::Job, JSON::Tiny

AUTHOR

Andrew Johnson, <lajandy at cpan dot org>

COPYRIGHT AND LICENSE

Copyright (C) 2014 by Logical Helion, LLC.

This library is free software; you can redistribute it and/or modify it under the terms of the Artistic License 2.0. See the included LICENSE file for details.

WARRANTY

This software comes with no warranty of any kind.