FEATURE AVAILABILITY STARTING FROM RELEASE 2.8.2

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.


(info) Users should review the JS7 - GraalVM Run-time Options, which define the security of the run-time environment, and the extension of standard modules as outlined in JS7 - How to add modules to GraalVM Python Jobs.

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
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 as a simple name-value map. 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 map of Arguments
class JS7Job(js7.Job):
    def processOrder(self, js7Step):
        # get map of all arguments
        args = js7Step.getAllArguments()
        js7Step.getLogger().info("[getAllArguments]:")
        js7Step.getLogger().info(f"all arguments: {args}")
  
        for arg_name, arg in args.items():
            js7Step.getLogger().info(f"argument: {arg_name}={arg.getValue()}")
       

Explanation:

  • The getAllArguments() method provides a map of all arguments as a name-JobArgument object map.
  • For further methods to access arguments see JS7 - Job API. 

Resources

How To ... GraalVM Python


  • No labels