Signaling from external API

Hello again all! And congrats to the Temporal team on the exciting funding announcement.

I have been trying to implement a signal method in an existing workflow, nothing crazy, just functions that update a class-level variable. However, I’m trying to trigger the pause from the UI of our web application and am receiving the error from Temporal, “Called from non workflow or workflow callback thread”.

To do this, I am sending a JSON with the workflow ID to the worker and it is using that to create a stub, and calling the signal method on that stub. I’m unclear on why I’m getting this error and would appreciate any guidance that could be offered.

Here is the code:

fun pauseWorkflow(ctx: Context) {
        val signalMessage = ctx.bodyAsClass(SignalMessage::class.java)
        val stub = Workflow.newExternalWorkflowStub(
                SingerWorkflowInterface::class.java, signalMessage.wfId)
        stub.pause()
        ctx.result("All good!")
    }

On a related note, I have been playing around with the temporal-web API to get workflow information and send terminate requests and finding that it works excellently. However, the “/api/namespaces/:namespace/workflows/:wfid/:rid/signal/:signal” endpoint does not signal the workflows, and gives me an error message: “SignalName length exceeds limit”. Any amount of characters triggers this error message, so is there something I am missing w/r/t this API?

Thanks in advance!

Thank you! Without the awesome open source community, all of this wouldn’t be possible.

Methods that belong to the Workflow class can be called only from within workflow threads. The external code should use WorkflowClient.newWorkflowStub instead. Here is a relevant Java SDK sample.

Thank you @maxim!