3.1 KiB
Rex
Rex executes chains of automations.
Those automations are generally user-defined executables, represented in a project structure as json objects.
Rex, when executing, is supplied a config file and a plan.
Config
The config file contains a json object that defines where the resources Rex will operate with are located on the filesystem, and the general project structure for the plan being executed.
Plans
A plan
is central to the operation of rex. It is a file containing a json
object that defines which units
to execute from the units library
. Once
a unit is specified in a plan
, it is referred to as a task
.
It should be noted that the config file and the plan file are not required to be separate files, but this is generally easier to manage from a project structure standpoint.
Library / Units
The units library
is generally where these automations are defined. This
is a directory containing files that end with the .units
suffix. Each of
those files is a json object with specifications for:
- What is being executed.
- How it is being executed.
- The context around which it is executed.
- An identifier by which the execution is referenced.
Exact specifications will be enumerated in a later section.
This allows these automations to executed with very tight control of the environment, current working directory, the execution process' owner and group context, whether a pty is used etc.
Among other things, the path for the units library is defined in the config file supplied at the command line to rex.
For reasons later explained, the presence of a unit definition in the units library does NOT mean that rex will execute that unit. It merely makes a unit available to be included as a task in a plan.
Self-Healing Workflows
Rex introduces self-healing workflows.
Model A
- Write a script that does a thing.
- Write a script that checks if that thing is done.
- Set up your check script as a target in a unit.
- Set up your script that does the thing as that unit's rectifier.
- Turn on the rectify pattern in the unit definition.
Model B
Or, if you want a flow that's more simple:
- Write a script that does a thing.
- Write a script that fixes any environmental conditions that prevent that thing from being done.
- Set up your target script to be the script that does the thing.
- Set up your rectifier script to be the script that fixes the bad condition.
- Turn on the rectify pattern in the unit definition.
Traditional Workflows
You don't need a dual mode of automation (though it is highly recommended). You can just do this:
- Write a script that does a thing.
- Set the user, group to run as, well as the shell that should be used to execute within.
- Set the environment file to a file to be sourced for that shell containing all of your environment definitions for your automation.
- Turn off the rectify pattern.
- Repeat for every step.
As you can see, for small automations, it's often going to be more desirable to just write a shell script, but for very large efforts spanning many subsystems or components, you may want more control -- that's really where Rex comes in.