A simple and efficient tool for running declarative workflows with ease.
Inspired by the projects Processus and Conductor.
We will discuss two distinct topics: defining a workflow and executing a workflow.
The Workflow Definition is the letrun primitive that encompasses the flow of your business logic. It contains all the information necessary to describe the behavior of a workflow.
A Workflow Definition includes a collection of tasks. This is the blueprint that specifies the order of task execution within a workflow. This blueprint also specifies how data/state is passed from one task to another.
Please refer to the Workflow Structure document for more details.
If Workflow Definitions are like OOP classes, then Workflow Executions are like object instances. Each time a Workflow Definition is invoked with a given input, a new Workflow Execution with a unique ID is created. Definitions to Executions have a 1:N relationship.
Like a workflow, a task can be considered in two parts: defining a task and executing a task.
Tasks are the building blocks of letrun workflows. Task Definitions appear within the tasks array/object property of the Workflow Definition. This tasks field is the blueprint that describes how a workflow will process an input payload by passing it through successive tasks.
A Task Definition includes a reference to the task type and the input necessary to execute the task. The input can be static or dynamic, based on the workflow's state.
Please refer to the Task Structure document for more details.
When a workflow is executed, each task within it is also executed. The executed task has a unique ID and represents the result of the operation, also includes the status, any input, output associated with the task.
Ensure you have Node.js (>=20) and npm (>=10) installed.
To install the CLI tool, run:
npm install -g @letrun/cli
Or use it directly with npx:
npx @letrun/cli <command> [options]
Alternatively, you can download the standalone executable file from the releases page.
Run a workflow defined in a JSON or YAML file with the CLI tool:
letrun run <workflow-file>
If you want to run a workflow programmatically, you can use the engine library
- Make sure you have installed the
@letrun/engine
package:
npm install @letrun/engine
- Then you can run a workflow programmatically:
import { DefaultRunner } from '@letrun/engine';
const runner = DefaultRunner.create();
try {
const result = await runner.run(
{
name: 'simple-workflow',
tasks: [
{
name: 'task1',
handler: 'lambda',
parameters: {
expression: '"Hello ${input.name}"',
},
},
],
},
{
name: 'world',
},
);
console.log('Workflow result: ', result);
} finally {
await runner.unload();
}
We have several commands to interact with the CLI tool:
letrun [command] [options]
- run: Execute a workflow defined in a JSON or YAML file.
- workflow: Manage saved workflows.
- plugin: Manage plugins.
- task: View and manage custom tasks.
Plugins are used to extend the functionality of the CLI tool. All the main features are implemented as plugins (system plugins), so any of them can be replaced or extended by custom plugins.
Plugins can provide additional features, or even modify the execution behavior.
See more details in the Plugin document.
The CLI tool can be configured using a configuration file or environment variables. The configuration provider will look up in this order:
letrun.mjson
in the runner directory.letrun.yaml
in the runner directory.letrun.yml
in the runner directory.- Lookup from environment variables.
The lookup key can be JSON path format, e.g.,
plugin.dir
will be either theplugin.dir
field ordir
field inplugin
object in JSON format. The YAML format will be converted to JSON format before lookup.
When lookup a key, we will use the following priority: exact key -> uppercase key -> camelCase key -> kebab-case key.
The default configuration is:
{
"plugin": {
"dir": "plugins"
},
"task": {
"dir": "tasks"
},
"persistence": {
"dir": "data"
},
"logger": {
"level": "debug",
"console": {
"showMeta": true,
"metaStrip": "timestamp,service",
"showTimestamp": true,
"timestampFormat": "HH:mm:ss.SSS",
"inspectOptions": {
"depth": -1,
"colors": true,
"maxArrayLength": -1,
"breakLength": 120,
"compact": -1
}
}
},
"interpolator": {
"maxRecursionLevel": 10
}
}
- Node.js (>=20)
- npm (>=10)
There are four projects:
core
: The core library that contains the shared types, interfaces, and utilities.common
: Common types and utilities which are independent from the runtime environment.plugin
: The plugin library that contains the system plugins.task
: The task library that contains some custom tasks.deps
: Provides a way to manage dependencies for the CLI tool.engine
: The engine library that contains the workflow engine, you can run a workflow programmatically.cli
: The CLI tool 😉
- Clone the repository:
git clone https://github.com/sontx/letrun.git
- Install dependencies:
npm install
- Build the projects:
npm run build
- Run the CLI tool:
cd dist
node letrun.mjs <workflow-file>
This project is licensed under the MIT License - see the LICENSE file for details.