mercredi 2 septembre 2015

SWF: End workflow based on Promise

I have a decider that calls an activity. The activity returns a list of validation errors. If the decider receives that list and it's not empty, I want to exit out of the workflow.

To exit the workflow I can just return in the decider, and it exits the workflow. The problem is that I'm not able to get the result from the activity. I'd have expected this to work, but it doesn't.. violations.isReady() always returns false:

public class WorkflowImpl implements Workflow {
    ActivitiesClient activities;

    public Workflow(/*...*/) {
        // ...
    }

    @Override
    public void do(WorkflowInput input) {
        Promise<List<String>> violations = activities.validate(input);

        if (!violations.isReady()) { // "do()" will be called when violations is ready.. right?
            return;
        } else if (!CollectionUtils.isEmpty(violations.get())) {
            return; // or throw ValidationException
        }

        // do other stuff
    }
}

I don't want to do the alternative which is to poll for violations.isReady() to be true, because this will tie up the decider thread for who knows how long. I'm not even sure if that would work.

Help?




Aucun commentaire:

Enregistrer un commentaire