Tutorial: Create a Process with MESG

Serg Stepanov
3 min readDec 7, 2019

--

Orchestration system

MESG Orchestrator is an event-driven task-orchestration system that manages the connections between the events and tasks of services by following the steps described by processes.

It lets you build and run complex applications by describing their business logic, then the Engine executes them for you.

Processes are an evolution of Applications as they are managed by the Engine and will be distributed on the upcoming decentralized network.

What is a process

Processes are nondeterministic finite state machines that perform state transition when matching events or a task’s results occur but don’t support the cycle.

Process can be graphically represented as UML activity diagram with actions and conditions, but without cycles and concurrency. Graphic representation is a very good first step to conceptualize an application before implementing it.

A process is a list of steps that describes a specific business logic.

Step can be one of the following:

  • Event trigger
  • Task’s result trigger
  • Execute a task
  • Condition on the data

Only the first step of a process is and must be an event or a task’s result trigger.

Validators

First of all, at least one Engine needs to be a validator of the network in order to create new blocks that contain the services and maintain the security of the network.

If you start the Engine on a fresh install (no ~/.mesg folder) it will automatically create a network with the Engine as the only validator.

Process file

A process file describes the connections between events and tasks of services with a step-by-step system.

It is structured in the following way:

Name Type Description key string Key to identify the process.steps Step[] Steps to execute.

Steps

Each step is one the following types:

  • Trigger: listen to an event or a task’s result
  • Task: execute a task
  • Filter: condition on the data

Trigger

The first step must be a trigger that listens for a specific event or result of a task to start the process.

Event

Name Type Description key string (optional) Key to identify this step.instanceHash string Hash of the service’s instance.eventKey string Event key to listen to.

Result

Name Type Description key string (optional) Key to identify this step.instanceHash string Hash of the service’s instance.taskKey string Task’s key of the result to listen to.

Task

This type defines which service’s task to execute.

By default, the task’s inputs are the previous step’s outputs. Can be customized by mapping the outputs of any previous steps.

Constant A constant lets you hardcode a value.

The value can be of any type: string, object, array, bool, number.

Filter

Apply one or multiple conditions on the previous step’s outputs.

All conditions should match to continue to the next step.

Triggers and tasks must have a specific instanceHash but this can be resolved automatically by the compiler if it replaced by an object instance containing the following:

Name Type Description service string Service’s sid or hash to start. Cannot be used with src.src string Path of the service to deploy and start. Local and remote path are supported. Cannot be used with service.env string[] List of environment variables to inject in the instance. Should respect the format: VARIABLE=value

Example

This is an example of process-file.

key: erc20-notification
steps:
- type: trigger
instance:
src: https://github.com/mesg-foundation/service-ethereum-erc20
env:
- PROVIDER_ENDPOINT=$(env:PROVIDER_ENDPOINT)
eventKey: transfer
- type: task
instanceHash: "H74Qqq8nT5JZ9GSJmuSWLN5benWZPkUb5pYcvQLsoZX"
taskKey: taskY
inputs:
inputA: "Input1 to the task"
# or
inputB:
stepKey: taskX
key: taskZ
- type: filter
conditions:
contractAddress: "0x420167d87d35c3a249b32ef6225872fbd9ab85d2"
- type: task
instance:
src: ./convert
taskKey: email
- type: task
instance:
src: https://github.com/mesg-foundation/service-email-sendgrid
env:
- SENDGRID_API_KEY=$(env:SENDGRID_API_KEY)
taskKey: send

Environmental variable

You can override any value in the process file during the compilation by using the following syntax:

$(env:XXXX)

Where XXXX is the name of the variable that you can override while running the compile command with the flag --env XXXX=value.

Help us improve this page!

--

--