# 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.

# Example

key: erc20-notification
steps:
  - type: trigger
    instanceHash: "H74Qqq8nT5JZ9GSJmuSWLN5benWZPkUb5pYcvQLsoZX"
    eventKey: eventX # listen to the event with the key `eventX`
    # or
    taskKey: taskX # listen to the result of the task with the key `taskX`
  # ...

WARNING

A process has only one trigger and it must be within the first step.

# 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.

Name Type Description
key string (optional) Key to identify this step.
instanceHash string Hash of the service's instance.
taskKey string Task key to execute.
inputs map<string, Input> (optional) Task's inputs. If not defined, inputs are the previous step's outputs.

# Input

Each input can be:

  • A constant.
  • A reference to the outputs of a previous step in the process.
# Constant

A constant lets you hardcode a value.

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

# Reference

Reference the outputs of a previous step.

Name Type Description
stepKey string (optional) Key of the previous step (defined with the attribute key of the step). If not defined, the previous step is used.
key string Key of the step's outputs to reference.

# Example

key: erc20-notification
steps:
  # ...
  - type: task
    instanceHash: "H74Qqq8nT5JZ9GSJmuSWLN5benWZPkUb5pYcvQLsoZX"
    taskKey: taskY
    inputs:
      inputA: "Input1 to the task"
      # or
      inputB:
        stepKey: taskX
        key: taskZ
  # ...

# Filter

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

All conditions should match to continue to the next step.

Name Type Description
conditions map<key, string> Key-value map where the key references a data of the previous steps outputs and the value is the expected matching value.

# Example

key: erc20-notification
steps:
  # ...
  - type: filter
    conditions:
      recipientID: "XXX"
      contractAddress: "0x420167d87d35c3a249b32ef6225872fbd9ab85d2"
  # ...

# Instance resolution

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

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
    instance:
      service: "serviceX" # Start the service with sid or hash value `serviceX`
      env:
          - SENDGRID_API_KEY=$(env:SENDGRID_API_KEY)
    taskKey: send
  - type: task
    instanceHash: "H74Qqq8nT5JZ9GSJmuSWLN5benWZPkUb5pYcvQLsoZX"
    taskKey: task1
  # ...

WARNING

To support this feature, you need to compile the process with the --dev flag.

# 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.