Signal A Workflow Using Only WorkflowId

Hello, is there a way to signal using only a WorkflowId? Please excuse me if that’s too naive a question to ask, but thought I would start with the shortest path.

Context

  1. All workflow types will have the same WorkflowId. So we expect, that we will have at most 1 such workflow running at any given time.
  2. The signal args are the same for each workflow type.
  3. Assuming I understood that signal names have to be unique across workflow types, I’m considering implementing and registering the same Dynamic Signal Handler for both types.
  4. So it seems to me that if I just had a way to signal the workflowId, no matter the workflow type, then I could simplify my current solution:
  • Create workflow stubs for all existing workflow types.
  • Signal all workflow types.
  • Catch WorkflowNotFoundException and any other unexpected exceptions that might arise for any one of those workflow types.
  • (I can imagine the complexity increasing if we introduced more workflow types.)

I work primarily with the Java SDK but I suppose the solution if it existed could be agnostic to the SDK?

In Java SDK you can use workflow interface inheritance. The base interface defines the signal method and each workflow type inherits from that. When signaling workflow the base interface can be used.

For example:

public interface Retryable {
    @SignalMethod
    void retryNow();
}

@WorkflowInterface
public interface FileProcessingWorkflow extends Retryable {

    @WorkflowMethod
    String processFile(Arguments args);

    @QueryMethod(name="history")
    List<String> getHistory();

    @QueryMethod
    String getStatus();

    @SignalMethod
    void abandon();
}

@WorkflowInterface
public interface MediaProcessingWorkflow extends Retryable {

    @WorkflowMethod
    String processBlob(Arguments args);
}

Signaling using base interface only:

Retryable r1 = client.newWorkflowStub(Retryable.class, firstWorkflowId);
Retryable r2 = client.newWorkflowStub(Retryable.class, secondWorkflowId);
r1.retryNow();
r2.retryNow();
1 Like

Thank you! I will try this and report back. I thought I read somewhere that there were some limitations with inheritance so I didn’t think to try that approach. (I probably confused it with this)

This would be a very nice solution if we can get it to work!

For our simple case, we’ve tested this solution and it’s enough. We’ll have to see how things go in production! Thanks for the help! Marked that as the solution.