danielgmyers / flux-swf-client

Apache License 2.0
8 stars 3 forks source link

Wait external event to continue workflow execution #109

Open waglero opened 1 year ago

waglero commented 1 year ago

Hello @danielgmyers. I am trying some tools for a new project and Amazon SWF looks like a nice alternative. Googling about it, I found your library, and it seems like it would make coding the integration with SWF a lot easier. One thing i am not certain is how to architect a workflow with a step that pauses and wait for an external event (a sqs listener for example). For what i have seen from the examples it isn't possible, but maybe i missed something. Is it possible with this client?

danielgmyers commented 1 year ago

Not directly. I'm going to keep this issue open while I consider ways to build this kind of thing directly into the library.

In the meantime the way I typically handle this kind of scenario is to have a workflow step that just checks whether it's safe to proceed (e.g. check if the resource is ready, if there's a message in the queue, if the database record is present, etc) and if not, retry by throwing an exception or returning StepResult.retry().

Something like this:

public class WaitForResource implements WorkflowStep {
    @StepApply
    public StepResult checkIfReady(@Attribute("resourceId") String resourceId) {
        if (!resourceIsReady(resourceId)) {
            return StepResult.retry("Resource isn't ready yet!");
        }
        return StepResult.success();
    }
}

By default this will do exponential backoff on the retries, so you may want to tune the retry timing parameters (see @StepApply for more details).

This won't work in all cases (like waiting for a push notification) but hopefully it's enough to get started.

waglero commented 1 year ago

Ok. Thanks for the fast response.