Multi Step Workflow

Learn how to handle complex execution flow orchestrating the execution of multiple nodes

Multiple steps are created by defining custom events that can be emitted by nodes and trigger other nodes. Let's define a simple 3-step workflow.

Custom Events

We define two custom events, FirstEvent and SecondEvent. These classes can have any names and properties, but must implement Event:

namespace App\Neuron;

class FirstEvent implements Event 
{
    public function __construct(protected string $firstMsg){}
}

class SecondEvent implements Event 
{
    public function __construct(protected string $secondMsg){}
}

Defining the workflow

Now we define the workflow itself. We do this by defining the input and output types on each node.

php vendor/bin/neuron make:node App\\Neuron\\InitialNode

php vendor/bin/neuron make:node App\\Neuron\\NodeOne

php vendor/bin/neuron make:node App\\Neuron\\NodeTwo

Here is the minimal implementation for the purpose of this demo:

Define the Workflow attaching the nodes:

The full output will be:

Of course there is still not much point to a workflow if you just run through it from beginning to end! Let's do some branching and looping.

Monitoring & Debugging

Before moving into the Workflow creation process, we recommend having the monitoring system in place. It could make the learning curve of how Workflow works much easier. The best way to monitoring Workflow is with Inspectorarrow-up-right.

After you sign up at the link above, make sure to set the INSPECTOR_INGESTION_KEY variable in the application environment file to monitoring Workflow execution:

Last updated