External Events
info
Before you can use an ExternalEventDef
in a WfSpec
, you need to create the ExternalEventDef
metadata object in LittleHorse. You can do that following our metadata management docs.
You can use WorkflowThread#WaitForEvent()
to add an EXTERNAL_EVENT
Node that causes the WfRun
to block until an ExternalEvent
arrives. It's simple:
- Java
- Go
- Python
- C#
public void workflowLogic(WorkflowThread thread) {
NodeOutput eventOutput = thread.waitForEvent("my-event-name");
}
func workflowLogic(thread *littlehorse.WorkflowThread) {
eventOutput := thread.WaitForEvent("my-event-name")
}
def workflow_logic(thread: WorkflowThread) -> None:
ext_event_output = thread.wait_for_event("my-event-name")
public void WorkflowLogic(WorkflowThread thread)
{
NodeOutput eventOutput = thread.WaitForEvent("my-event-name");
}
Accessing Event Content
Lastly, just as with TASK
nodes you can use the NodeOutput
from WorkflowThread::waitForEvent()
to mutate a WfRunVariable
:
- Java
- Go
- Python
- C#
public void workflowLogic(WorkflowThread thread) {
WfRunVariable myVar = thread.declareJsonObj("my-var");
NodeOutput eventOutput = thread.waitForEvent("my-event-name");
myVar.assign(eventOutput);
}
func workflowLogic(thread *littlehorse.WorkflowThread) {
myVar := thread.DeclareJsonObj("my-var")
eventOutput := thread.WaitForEvent("my-event-name")
myVar.Assign(eventOutput);
}
def workflow_logic(thread: WorkflowThread) -> None:
my_var = thread.declare_json_obj("my-var")
event_output = thread.wait_for_event("my-event-name")
my_var.assign(event_output)
private static void WorkflowLogic(WorkflowThread thread)
{
WfRunVariable myVar = thread.DeclareJsonObj("my-var");
NodeOutput eventOutput = thread.WaitForEvent("my-event-name");
myVar.Assign(eventOutput);
}
note
If you use an ExternalEventDef
for any EXTERNAL_EVENT
node as shown in this tutorial, you cannot re-use that ExternalEventDef
as a trigger for Interrupts.