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
public void threadFunction(WorkflowThread thread) {
NodeOutput eventOutput = thread.waitForEvent("my-event-name");
}
func someThreadFunction(thread *littlehorse.WorkflowThread) {
eventOutput := thread.WaitForEvent("my-event-name")
}
def thread_function(thread: WorkflowThread) -> None:
ext_event_output = thread.wait_for_event("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
public void threadFunction(WorkflowThread thread) {
WfRunVariable myVar = thread.addVariable("my-var", VariableType.JSON_OBJ);
NodeOutput eventOutput = thread.waitForEvent("my-event-name");
thread.mutate(myVar, VariableMutationType.ASSIGN, eventOutput);
}
func someThreadFunction(thread *littlehorse.WorkflowThread) {
myVar := thread.AddVariable("my-var", lhproto.VariableType_JSON_OBJ)
eventOutput := thread.WaitForEvent("my-event-name")
thread.Mutate(myVar, lhproto.VariableMutationType_ASSIGN, eventOutput);
}
def thread_function(thread: WorkflowThread) -> None:
myVar = thread.add_variable("my-var", VariableType.JSON_OBJ)
event_output = thread.wait_for_event("my-event-name")
thread.mutate(myVar, VariableMutationType.ASSIGN, event_output)
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.