Introduction

JS7 offers a number of JS7 - Job Classes for Shell Jobs and JVM 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.

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:

Example for implementation of JS7Job with Python
class JS7Job(js7.Job):
    def processOrder(self, js7Step):
        js7Step.getLogger().info("hello world")
        # do some stuff


Explanation:

  • The implementation class with the name JS7Job is required.
  • The processOrder() method is required to be implemented by the job.
    • The method is parameterized by the js7Step object provided by the Job API.
    • The js7Step object is used with its getLogger() method to write output to the job's log.

Accessing Arguments

A Python Job can access arguments from a number of sources, see JS7 - Job API

Example: Reading specific Arguments

Example for implementation of JS7Job with Python
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

Example for implementation of JS7Job with Python
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

How To ... GraalVM Python



  • No labels