carlosm
carlosm

Reputation: 755

Finish workflow when activity goes wrong

I have a workflow that executes a couple of activities. When the activity finish, it returns an Outcome either Done or Cancel, from outside and before running the next activity, I need to check if the previous activity was ok or not, in case not, I need to cancel the workflow. I have this

public class CreateEmployee : IWorkflow
{        
    public void Build(IWorkflowBuilder builder)
    {
        builder
            .WithDisplayName(this.GetType().Name)
            .Then<GetDataById>(x => x.WithDisplayName(x.ActivityType.Name))
            .When(OutcomeNames.Cancel).Finish()
            .Then<InsertEmployee>(x => x.WithDisplayName(x.ActivityType.Name))
            .When(OutcomeNames.Cancel).Finish()
            .Then<InsertMapping>(x => x.WithDisplayName(x.ActivityType.Name))
            .When(OutcomeNames.Cancel).Finish();
    }  
}

For example, after executing activity GetDataById, if the return is "Cancel", I call Finish(), is this going to stop just the activity and continue the workflow or the workflow will stop completely? I'm not able to test it because I'm using DI and I need to prepare the whole unit test, because I didn't find anything directly related to cancel the whole workflow

Upvotes: 0

Views: 562

Answers (1)

VahidNaderi
VahidNaderi

Reputation: 2488

I'm not sure if I have fully understood your question, but in the documentation about finish activity it's stated that:

when this activity is used within a workflow, the workflow instance will enter the Finished state. When used in a child composite activity, that activity will stop execution and yield back control to its container. However, it will not stop workflow execution itself.

Upvotes: 0

Related Questions