I have a use case where I need to signal my current workflow execution. I have this working locally with unit tests (using TestWorkflowEnvironment
) but the same code results in a SIGNAL_EXTERNAL_WORKFLOW_EXECUTION_FAILED_CAUSE_EXTERNAL_WORKFLOW_EXECUTION_NOT_FOUND
when run against a real Temporal server.
The workflow impl follows the basic pattern of:
- Using a
Workflow.newWorkflowQueue
- A signal method that will call
WorkflowQueue.put
against the queue - The main workflow calls
WorkflowQueue.take
in a loop
Before blocking on the queue, the workflow kicks off an async procedure as follows:
val scope = Workflow.newCancellationScope(Runnable { pollForSomeCondition() })
Async.procedure { scope.run() }
fun pollForSomeCondition() {
while (true) {
Workflow.sleep(Duration.ofHours(1))
if (getSomeConditionViaActivity()) {
signalThisWorkflow("hello")
break
}
}
}
fun signalThisWorkflow(msg: String) {
val workflowId = Workflow.getInfo().workflowId
val thisWorkflow = Workflow.newExternalWorkflowStub(
SimpleWorkflow::class.java, // same as current workflow
workflowId
)
thisWorkflow.signal(SignalInput(msg))
}
In the workflow history, I see a SignalExternalWorkflowExecutionInitiated
followed by the following:
(sensitive data redacted in yellow but is not empty)
The workflow then hangs until it eventually times out with WorkflowExecutionTimedOut
.
I do not understand why this signal is failing. The workflow clearly exists as we’re signalling ourselves, and the same code works correctly in a test environment. Could anyone please shed any light on why this is failing? And if there’s no simple fix, would a work-around be to invoke the workflow via a WorkflowClient
in an activity?
Thanks!