Workflow Implementation


A workflow is where the control flow is described, while tasks are where the actual works are done. A workflow is described in node.js in a file required in the Agent boot file:

  • it must contain a handle generator function
  • it may contain an onEvent generator function

The handle and onEvent functions describe respectively the main sequence of tasks and what to do when receiving an event. This description is done using Zenaton functions.

# Handle Generator Function

The simplest form of a workflow is an object with a handle key containing a generator function:

module.exports.handle = function* (...input) {
    // workflow description 
};

the input array above is the <workflow input> array provided when dispatching a workflow.

This generator function describes the order in which actions should be processed and usually include some data processing.

# OnEvent Generator Function

You can optionaly define an onEvent generator function:

module.exports.onEvent = function* (eventName, ...eventData) {
    // what to do when receiving an event
};

Like the handle function, the onEvent generator function describes the order in which actions should be processed, in reaction to an event. Typically, onEvent starts with a test on eventName to decide what to do based on the event's type.

TIP

Contrary to the handle function, the onEvent function is triggered each time an event is received by a workflow.

# Zenaton functions

A workflow is defined using functions available inside the handle and onEvent generator functions:

  • this.run - to dispatch tasks or sub-workflows.
  • this.wait - to wait for duration, a date or an external event.
  • this.schedule - to schedule a recurrent dispatch of a task or a workflow.
  • this.send - to send an event to a workflow.
  • this.pause - to pause a workflow.
  • this.terminate - to terminate a workflow.
  • this.select - to select some workflows, and apply a send, pause, resume or terminate.