Scripting Jobs

From Obsidian Scheduler
Jump to: navigation, search

Obsidian provides support for execution of scripted jobs in various languages. None of these require any Java code to be written. The script to execute is set via a script job parameter. Jobs are executed under the context of the process user running Obsidian.

The following job classes can be configured with executable scripts in their target languages:

  • com.carfey.ops.job.script.JavaScriptJob running Rhino
  • com.carfey.ops.job.script.PythonJob running Jython
  • com.carfey.ops.job.script.GroovyJob Groovy
  • com.carfey.ops.job.script.BeanShellJob executing a BeanShell script.
  • com.carfey.ops.job.script.ReflectiveJob is a convenience GroovyJob that does not require a script, using defined parameters to construct an object and invoke method(s), both supporting argument(s)
  • com.carfey.ops.job.script.SpringBeanJob is a convenience GroovyJob that does not require a script, using defined parameters to obtain the bean and invoke the method(s). Deprecated as of Obsidian 2.2.0. Use Dependency Injection instead.

Parameters

Any parameters configured for the job will be set as global variables within the script. If a single value is configured for a parameter, it will be set as its direct type. If multiple values are set for a parameter, it will be passed into the script as a list of values.

Loading Scripts from the File System

As of Obsidian 2.4, all script file jobs can now use a script file path instead of configuring the script directly in Obsidian. When the job runs, Obsidian will load the contents of the file and execute the script in the same way that jobs configured using the script parameter are run.

To use this feature, when configuring the job, omit the script parameter and instead supply a file path under Script File Path. It is recommended that an absolute path is used, and the Obsidian process will need read access to the file for it to run successfully.

Job Context

The job context variable is accessed through the global variable named "jobContext". This can be used to save output parameters, etc. See Job Results and Parameterization.

Sample Jobs

Groovy:

GroovyConfig.png


Python:

PythonConfig.png


Javascript:

JavascriptConfig.png

SpringBeanJob

Deprecated as of Obsidian 2.2.0. Use Dependency Injection instead. A SpringBeanJob is simply a convenience GroovyJob with a predefined script that uses some specified parameters to find a Spring Bean and invoke specified method(s). Specify any optional class imports (class names only), the single line of code to retrieve the Spring Bean reference and the method name(s) to invoke.

SpringBeanJobSample.png

Running Ruby from Obsidian

Obsidian can be configured to run Ruby via JRuby. Native support isn't provided due to conflicts between Jython support and JRuby. If you are willing to drop Jython(Python) support in Obsidian, you may follow these instructions to enable JRuby support.

  1. Download JRuby JAR and replace the Jython JAR (jython-standalone-2.5.3.jar) with the JRuby JAR.
  2. Add the RubyJob source below. Either incorporate into your existing job building process or compile and statically add to your Obsidian deployment.
  3. Note the sample configuration below.
/*
The MIT License (MIT)

Copyright ©2016 Carfey Software Corporation. All rights reserved.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

*/
package com.carfey.ops.job.script;

import com.carfey.ops.job.param.Description;


/**
 * <p>
 * <b>Usage: </b>
 * See [email protected] ScriptEngineJob}. 
 * This is a script job using the ruby engine,
 * which by default is the <a href="http://jruby.org/">JRuby</a> implementation.
 * 
 * 
 * @see <a href="http://obsidianscheduler.com/wiki/File:Obsidian.3.6.0.RubySampleJob.PNG">Sample Configuration</a> 
 */
@Description("This job will execute the supplied Ruby script, with custom parameters inserted into the script variable context. " +
        "Either an inline script or the full script path may be supplied.")
public class RubyJob extends ScriptEngineJob {

    @Override
    protected String getEngineName() {
        return "jruby";
    }

}

RubyConfig.png