Interruption
The key breakthrough is that interruption isn't a bug, it's a feature.
How it works
namespace App\Neuron;
use NeuronAI\Workflow\Events\Event;
use NeuronAI\Workflow\Interrupt\Action;
use NeuronAI\Workflow\Interrupt\ApprovalRequest;
use NeuronAI\Workflow\Node;
use NeuronAI\Workflow\WorkflowState;
class ApprovalNode extends Node
{
public function __invoke(PurchaseEvent $event, WorkflowState $state): Event
{
// Suspend the workflow, carrying the request OUTBOUND.
$payload = $this->interrupt(
new ApprovalRequest(
message: 'Do you approve this purchase?',
actions: [
new Action(
id: 'purchase_1',
name: 'Purchase',
description: "Buy {$event->item} for {$event->price}$",
),
],
)
);
// Code below this line runs ONLY on resume.
// $payload is the INBOUND answer delivered by resume() — your node interprets it.
if (($payload['purchase_1'] ?? null) === 'approve') {
return new PurchaseApprovedEvent();
}
return new PurchaseRejectedEvent();
}
}The Persistence layer
Catching the interruption
Resuming
Conditional interruption
Custom interruption request
Waiting for an external event
Consuming the feedback
Durable steps and memoize()
Last updated