You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 5 Next »

The JobScheduler supports different javascript engines: spidermonkey and rhino

  • The spidermonkey engine is only available on 32 bit. It is selected by <script languagh1. "javascript"> or <script language"spidermonkey">
  • The rhino (pur java) is available on 32 bit and 64 bit. It is selected by <script languagh1. "javax.script:rhino">
  • The "Rhino with Beans" engine is available on 32 bit and 64 bit. It is selected by <script language"java:javascript">

language

32bit

64bit

spidermonkey

spidermonkey

javascript

spidermonkey

javax.script:rhino

rhino

rhino

java:javascript

rhino (with beans)

rhino (with beans)

If you want to migrate a javascript for spidermonkey to a 64Bit JobScheduler then in most cases you must only change the language attribute to <script language="java:javascript">. But this works only nearly.

Migrate Javascript from Spidermonkey to Rhino

We recommend to change the JavaScript to the Rhino (pure java) syntax. Then it works properly on 32Bit and 64Bit JobScheduler.

Rhino doesn't have properties. You have to use "setter" and "getter" instead.

Please look at the API documentation for more details.

syntax examples

  • spidermonkey
 // log job name and tsk id
 spooler_log.info(spooler_job.name + " is running with task id " + spooler_task.id);
 // add an order
 var order = spooler.create_order();
 order.title = "this is an order";
 order.id = "my order id";
 spooler.job_chain( "/path/to/job chain/job chain name" ).add_order( order );
 // set a job state text
 spooler_job.state_text = "OK!";
 // read and write parameter from the current order
 var orderParams = spooler_task.order.params;
 var myParam = orderParams.value("myParam");
 orderParams.value("myParam") = "new value";
  • javax.script:rhino (pure java)
 // log job name and tsk id
 spooler_log.info(spooler_job.name() + " is running with task id " + spooler_task.id() );
 // add an order
 var order = spooler.create_order();
 order.set_title("this is an order");
 order.set_id("my order id");
 spooler.job_chain( "/path/to/job chain/job chain name" ).add_order( order );
 // set a job state text
 spooler_job.set_state_text("OK!");
 // read and write parameter from the current order
 var orderParams = spooler_task.order().params();
 var myParam = orderParams.value("myParam");
 orderParams.set_value("myParam", "new value");
  • Using the rhino engine there are no javascript reserved words allowed.

The following code can't be executed with the "Rhino with Beans" engine:

 var file = new java.io.File(files[i]);
 file.delete();

Since delete is a reserved word in javascript the code above results in the following error:

 javax.script.ScriptException: sun.org.mozilla.javascript.internal.EvaluatorException: missing name after . operator (<Unknown source>#26) in <Unknown   source> at line number 26
       at com.sun.script.javascript.RhinoScriptEngine.eval(Unknown Source)
       at com.sun.script.javascript.RhinoScriptEngine.eval(Unknown Source)
       at javax.script.AbstractScriptEngine.eval(Unknown Source)
       at com.sos.scheduler.scripting.Module.call(Module.java:76)
       at com.sos.scheduler.scripting.Module.callBoolean(Module.java:85)

Solution:

 var file = Packages.java.io.File(files[i]);
 file["delete"]();				// because delete is reserved in javascript
  • No labels