Overview
With workflows, you can automate many things in Brezel. They are programs that should perform a single task in your business logic.
Structure
Sync/Async
Workflows can be either sync
or async
. Synchronous workflows are executed and completed synchronously in the same process (usually during the HTTP request cycle), while asynchronous workflows are queued and executed by a process running in the background.
If a workflow runs actions that send HTTP responses, they should be made sync
and need to be called during a HTTP request.
Actions that take longer than the recommended 30 seconds execution time should be made async
.
Elements
Workflows always consist of at least one element. A workflow element is the basic building block of a workflow – it can be plugged into other elements, can receive and output data through its ports, carry context information as well as be configured with options that control its behavior.
Here is a very simple workflow:
The first element here is of type source/entities
. The second element is the built-in action/log
element that is used
to log data to the console.
You can see that we give the element a name and type. The type is always in the format <category>/<type>
. The name is required so that other elements can reference it.
The options
property is unique to each element and allows to configure the behavior of that element. For example, the
action/log
element can have the level
option set to info
, warn
, error
or debug
.
The to
property is where we define the connections of this element. More on that in the next section.
Ports
Elements have ports. Ports are used to exchange data between elements. Ports can be either input or output ports. Elements can have multiple ports of each type.
The example workflow above has two ports:
- The default output port of the
source/entities
element. - The default input port of the
action/log
element.
You can see that we define the connections in the to
property of the source/entities
element.
Connections
Connections define how data flows between elements. Each connection is a link between a port of the first element and a port of the second element. Connections are uni-directional, meaning that data can flow from the first element to the second but not the other way around.
In the example workflow above, we have defined a connection from the default
port of the source/entities
element to the
default
port of the action/log
element. This connection defines that any data that comes out of the default
port of the
source/entities
element will be forwarded to the default
port of the action/log
element.
Connections can be defined in the to
property of elements, between a port of the first element and multiple ports of the second element.