Introduction
JS7 offers a number of JS7 - Job Classes for Shell Jobs and JVM Jobs.
- Users can implement jobs using Python from JS7 - Shell Jobs.
- Users can implement jobs using Python from JS7 - GraalVM Jobs
GraalVM Jobs can be executed with any supported Java Virtual Machine (Oracle, OpenJDK). This allows use of the Oracle® GraalVM but does not require this flavor of the JVM.
- The Oracle® GraalVM implements Python 3.x depending on the version of the GraalVM Polyglot interface and Graal compiler in use.
- For details how to bring Polyglot and Graal Compiler to JS7 Agents see JS7 - Adding and Updating Graal Libraries to Agents.
- The Oracle® GraalVM can similarly be used for JS7 - GraalVM JavaScript Jobs.
JS7 offers the JS7 - Job API to GraalVM 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.
Python jobs are available starting from the following releases:
FEATURE AVAILABILITY STARTING FROM RELEASE 2.8.2
Implementation
Implementing a basic Job
A Python Job is implemented by a class with the name JS7Job like this:
class JS7Job(js7.Job):
def processOrder(self, 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 Python 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 GraalVM Python Jobs
Example: Reading specific Arguments
class JS7Job(js7.Job):
def processOrder(self, js7Step):
logger = js7Step.getLogger()
# access argument by name
logger.info("[getAllArgumentsAsNameValueMap] by name:")
color_blue = js7Step.getAllArgumentsAsNameValueMap()["color_blue"]
logger.info(f"argument color_blue={color_blue}")
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
class JS7Job(js7.Job):
def processOrder(self, js7Step):
logger = js7Step.getLogger()
# Get list of all arguments
args = js7Step.getAllArguments()
# Unpacks Java argument wrappers and converts values to a clean Python dictionary
args_dict = {key: str(arg.getValue()) for key, arg in args.items()}
logger.info("[getAllArguments]:")
logger.info(f"all arguments: {args_dict}")
Explanation:
- The
getAllArguments()method provides an array of argument objects for iteration. - The
getValue()method by default returns a Java Object. To receive a string value, users must cast the result or use a method that enforces the string data type. - For further methods to access arguments see JS7 - Job API.
Resources
Features
Links
How To ... GraalVM Python