A chain is a set of processes with its own properties like scheduling, notifications, dependencies, outputs, etc.
This is an example of a basic chain with one process:
A chain has two identification fields:
id, identifies the chain. with this identifier Runnerty will provide a global value (:CHAIN_ID) that can be used in the whole chain. To know more about global values have a look here
name, it is a description of the chain. Runnerty will also provide the global value :CHAIN_NAME
There are different ways to schedule a chain. It is possible to schedule chains with a cron expression.
This scheduling will execute the chain at every minute:
There is also the possibility to schedule a chain using a calendars. The calendars path can be indicated in the config.json file:
Calendars can be used for both, enabling or disabling execution dates through the enable and disable properties, so it can be specified, for example, to only execute a chain on laboral days, excluding weekends, like in the sample below:
It is possible to define and overwrite global values at chain level, setting a custom_values attribute:
It is possible to define dependencies with other chains or other chains processes. This means than a chain with dependencies will never execute before their dependencies are resolved.
You can define these dependency restrictions through the depends_chains property, like in the sample below:
The chain of the example will not be executed until the chain with id CHAIN_ONE is finished. It is also possible to configure a set up dependencies to one chain’s process or more:
In addition, it is possible to set up file system path dependencies in Runnerty with the help of auto-magically configured filewatchers. Them are defined with the condition property and can be fired through the following actions:
- add: when a file is added.
- change: when a file is changed.
- unlink: when a file is deleted.
- error: when there is an error in the file treatment.
Usage example below:
With the notifications property, Runnerty can be set up to emit notifications during the chain status flow, fired up by the following callbacks:
In these notifications we could notify anything using notificators.
The following example shows how to set up notifications for the different states of the chain through Telegram Notificator, publishing messages to a previously defined Telegram’s chatroom:
Note the usage of the global value :CHAIN_ID on the previous example. This value will be replaced with the chain’s id. Know more about global values here
(List of avaliable officialy notificators coming out soon).
Learn more about notificators and how to configure them here.
In the processes array property can be defined all the processes that are going to be part of the chain.
Learn more about processes and how to configure them here.
An iterale chain is a chain that is going to be executed for each object in the array previously returned by another process.
For example, if we have a process which returns one objects array we can execute an iterable chain for each object in the array.
In the following example we are going to send an email to every user of the USERS table.
First, we have the chain get-users-email.json with a process which selects all the users’s email:
Then, we assign the returned resultset by the MySQL SELECT query as an object array with the PROCESS_EXEC_DATA_OUTPUT value, as part of the property output_iterable. This way we are announcing this process will return an iterable output.
Now we are going to define the iterable chain “send-mail-to-user”
Here we can see some properties that the chain needs to iterate. First of all we have the dependencies on the depends_chains property. An iterable chain must depends on the process from the “mother chain” whom it iterates:
With the iterable property we can choose if we want to iterate over in series or parallel:
With the input property we can assign the properties of each object returned by de mother’s process array.
Now, we can use these values anywhere in our iterable chain:
In the example :email will be replaced with the user’s email and :name will be replaced with the user’s name.