Introduction
JS7 offers a number of JS7 - Job Classes including JS7 - Shell Jobs, JS7 - Java Jobs and JavaScript Jobs.
- JavaScript Jobs require use of the Oracle® GraalVM Java Virtual Machine with the JS7 Agent The JVM provides the interpreter/compiler for JavaScript.
- The Oracle® GraalVM is compatible to ECMAScript standards depending on the version of the JVM in use.
JS7 offers the JS7 - Job API to JavaScript Jobs that serves the purpose of
- accessing arguments available to the job from various sources such as JS7 - Order Variables, job and node arguments, JS7 - Job Resources,
- allowing to specify the outcome of a job including return values that are passed to subsequent jobs from order variables.
JavaScript jobs are available starting from the following releases:
FEATURE AVAILABILITY STARTING FROM RELEASE 2.5.4
FEATURE AVAILABILITY STARTING FROM RELEASE 2.6.1
Implementation
Implementing a basic Job
A JavaScript Job is implemented by a class with the name JS7Job like this:
Example for implementation of JS7Job with JavaScript
class JS7Job extends js7.Job {
processOrder(js7Step) {
js7Step.getLogger().info( 'hello world' );
// do some stuff
}
}
Explanation:
- The implementation class with the name
JS7Jobis required. - The
processOrder()method is required to be implemented by the job.- The method is parameterized by the
js7Stepobject provided by the Job API. - The
js7Stepobject is used with itsgetLogger()method to write output to the job's log.
- The method is parameterized by the
Accessing Arguments
A JavaScript Job can access arguments from a number of sources, see JS7 - Job API.
- The straightforward way how to read arguments is explained from the next chapter.
- For more detailed access methods and examples see JS7 - How to read arguments in JavaScript Jobs
Example: Reading specific Arguments
Example for implementation of JS7Job with JavaScript
class JS7Job extends js7.Job {
processOrder(js7Step) {
// access argument by name
js7Step.getLogger().info('[getAllArgumentsAsNameValueMap] by name:');
var colorBlue = js7Step.getAllArgumentsAsNameValueMap()['color_blue'];
js7Step.getLogger().info('argument color_blue=' + colorBlue);
}
}
Explanation:
- The
getAllArgumentsAsNameValueMap()method provides a map of all arguments. The map allows to read a single argument from the argument name. - For further methods to access arguments see JS7 - Job API.
Example: Reading the list of Arguments
Example for implementation of JS7Job with JavaScript
class JS7Job extends js7.Job {
processOrder(js7Step) {
// get list of all arguments
var args = js7Step.getAllArguments();
js7Step.getLogger().info('[getAllArguments]:');
js7Step.getLogger().info('all arguments: ' + args);
for (var arg in args) {
js7Step.getLogger().info('argument: ' + arg + '=' + args[arg].getValue());
}
}
}
Explanation:
- The
getAllArguments()method provides an array of argument objects for iteration. - For further methods to access arguments see JS7 - Job API.
Further Resources
Features
Articles
Links
How To ... JavaScript
Overview
Content Tools