Interrupting Execution
Interruption operations are crucial for workflows that need to respond to cancellation requests or timeout conditions. This allows selecting an alternative path based on such a signal.
val MySignal = SignalDef[MyRequest, MyResponse]()
val doA = WIO.pure(MyState(1)).autoNamed
val doB = WIO.pure(MyState(1)).autoNamed
val interruption =
WIO.interruption
.throughSignal(MySignal)
.handleSync((state, request) => MyEvent())
.handleEvent((state, event) => MyState(0))
.produceResponse((state, event) => MyResponse())
.autoNamed
.andThen(_ >>> doB)
val interruptedThroughSignal = doA.interruptWith(interruption)
Rendering Outputs
- Flowchart
- BPMN
- Model
{
"base" : {
"meta" : {
"name" : "Do A",
"error" : null
},
"_type" : "Pure"
},
"trigger" : {
"meta" : {
"signalName" : "My Request",
"operationName" : "Interruption",
"error" : null
},
"_type" : "HandleSignal"
},
"handler" : {
"meta" : {
"name" : "Do B",
"error" : null
},
"_type" : "Pure"
},
"_type" : "Interruptible"
}
Drafting Support
Interruptions come with drafting support.
// Create signal and timeout interruptions
val urgentProcessing = WIO.draft.interruptionSignal("Urgent Processing Request")
val processingTimeout = WIO.draft.interruptionTimeout("Processing Deadline", 2.hours)
// Document processing workflow that can be interrupted
val documentProcessingWorkflow =
WIO.draft.step("Validate Document") >>>
WIO.draft
.step("Extract Content")
.interruptWith(urgentProcessing) // Can be interrupted for urgent processing
.interruptWith(processingTimeout) // Must complete within 2 hours
Rendering Outputs
- Flowchart
- BPMN
- Model
{
"steps" : [
{
"meta" : {
"name" : "Validate Document",
"error" : null,
"description" : null
},
"_type" : "RunIO"
},
{
"base" : {
"base" : {
"meta" : {
"name" : "Extract Content",
"error" : null,
"description" : null
},
"_type" : "RunIO"
},
"trigger" : {
"meta" : {
"signalName" : "Urgent Processing Request",
"operationName" : null,
"error" : null
},
"_type" : "HandleSignal"
},
"handler" : null,
"_type" : "Interruptible"
},
"trigger" : {
"meta" : {
"duration" : "PT2H",
"releaseAt" : null,
"name" : "Processing Deadline"
},
"_type" : "Timer"
},
"handler" : null,
"_type" : "Interruptible"
}
],
"_type" : "Sequence"
}