Skip to main content

Notice: this Wiki will be going read only early in 2024 and edits will no longer be possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.

Jump to: navigation, search

SMILA/Documentation/Worker/ScriptProcessorWorker

< SMILA‎ | Documentation
Revision as of 09:29, 29 October 2014 by Andreas.weber.empolis.com (Talk | contribs) (Configuration)

ScriptProcessorWorker (bundle org.eclipse.smila.scripting)

The ScriptProcessorWorker is a worker designed to process (synchronous) script calls inside an asynchronous workflow. The worker in principal is independent of a dedicated script processing implementation, however, in SMILA we use scripting with JavaScript.

The scripts that can be used for execution are those defined in the SMILA configuration: <SMILA>/configuration/org.eclipse.smila.scripting/js


Configuration

The ScriptProcessorWorker is configured via incoming task parameters. These parameters could have been set e.g. in a job definition.

Parameter Description Default value
script Required parameter for the name of the script (= filename without .js extension).

Additionally, each input record can contain an attribute "_script" with a single string value to choose a different script to process this record. If this attribute does not specify an existing script (or the value is not a single string), the script given by the task parameters is used to process the record (and a warning is written to the logfile).

---
function Optional parameter for the name of the script function to use for processing records.

Additionally, each input record can contain an attribute "_function" with a single string value to choose a different function to process this record. If this attribute value is not valid, the function given by the task parameters is used to process the record (and a warning is written to the logfile).

process
initializeFunction Optional parameter for the name of the script function called once to use for initializing the script. (This parameter can not be overwritten in the record.).

Hint: The script must implement the function - you can leave it empty if you don't need it, but it must be defined!

prepare
writeAttachmentsToOutput Optional parameter. By default, attachments on incoming records are also added to the output records (if any are written). If this parameter is set to false, only record metadata is written to the output bulk. This can save a lot of IO if attachments are not needed anymore in the workflow after this worker. true

Sample job definition that sets the parameters:

{
  "name":"myJob",
  "parameters":{
    "script": "myScript",
    "function": "myFunction",
    "initializeFunction": "myPrepare",
    ...
   },
  "workflow":"myWorkflow"
}

ScriptProcessorWorker definition

Can be found:

  • in the configuration file: configuration/org.eclipse.smila.jobmanager/workers.json
  • via REST API: GET /smila/jobmanager/workers/scriptProcessor

The output bucket of the worker is optional, hence in an asynchronous workflow the worker does not need to have a successor. If the output bucket is not defined, the result records of the script processing are not persisted to a bulk, but thrown away. This makes sense if the script stores the records somewhere itself, e.g. adds them to an index.

Access task parameters in pipelets

The worker adds all task parameters to a map in attribute _parameters in each record before giving it to the workflow processor, so each pipelet can access them. The helper class org.eclipse.smila.processing.parameters.ParameterAccesssor supports this by checking for requested parameters first in this _parameters map, then at the top-level of a record and then in the pipelet configuration. Therefore it's possible to override properties from the pipelet configuration by setting them as task parameters, if the pipelet uses the ParameterAccessor to access parameters in records and configuration. This is done for example by the SetValuePipelet.

If the internal parameter _failOnError was not set before, the worker will set the parameter to "false". This means that the called pipelets should continue processing records and not stop when processing defect records. The pipelets themselves must implement this behavior. How to achieve this is explained in How to write a Pipelet.

Error handling

The following errors may occur when a task for the PipelineProcessorWorker is processed:

  • Parameter sets an invalid value
    • If a script or function parameter is set to an invalid value, the task will fail with a non-recoverable error.
  • ScriptingEngineException while processing a record.
    • Recoverable ScriptingEngineException: The current task will fail with a recoverable error, so the whole task (with all records) will be repeated.
    • Non-recoverable ScriptingEngineException: An error will be logged and the worker will continue with the next bunch of records. The records of the current bunch will be lost. (This is implemented in a way as to not fail the whole task with all its input records in case of a single record defect.)

Back to the top