简体   繁体   中英

Will Child workflow continue to run after parent is finished? (ChildPolicy.ABANDON)

I want to trigger child workflows from one workflow(parent). Basically this would happen in a loop in the decider

@Workflow
@WorkflowRegistrationOptions(defaultExecutionStartToCloseTimeoutSeconds = 240,
              defaultTaskStartToCloseTimeoutSeconds = 60)
public interface W1{
    @Execute(version = "1.0")
    void fn();
}

public class W1Impl implements W1{
    ChildClientFactory factory = new ChildClientFactoryImpl();

    @Override
    public void fn() {
       int i;
      /*
          I'll call activity1 that returns me a list(size = n)
          I trigger n child worflows(Each takes the content in the list and operates)
      */
       for(i = 0; i < n; i++) {
          ChildClient childWorkflowClient = factory.getClient();
          childWorkflowClient.someMethod(params);//TRIGGERING CHILD WORKFLOW
      }
    }
}

The parent workflow need not wait for the child workflows to finish. ie) the child workflows will do some processing based on the input to them and will put the result in a persistance store. So I'm not returning a promise from the child workflows.

Note: Child workflow's decider return type is void .

The ChildPolicy option on WorkflowRegistrationOptions has the option ABANDON

From the docs:

ABANDON: Amazon SWF will take no action; the child executions will continue to run.

Questions:

  1. When I don't return any Promise from the child workflow, will the parent workflow finish after triggering all child workflows?

ie) after triggering n child workflows the parent must finish execution. The child will continue to run. (since i've specified ChildPolicy.ABANDON ). Is this correct?

  1. The defaultExecutionStartToClosetimeoutSeconds of parent need not consider(include) the timeout of the child workflows , right?

3.Are there any constraints on the rate at which child workflows are triggered? (Since I trigger workflows from a loop)

And is there anything that I need to take care of?

Thanks..

1) nope (updated). see Maxim's answer below 2) if you are abandoning them, the timeouts on the child workflows matter. Only thing you should worry about (as far as timeouts go) is that the parent workflow will timeout before getting a chance to launch all child workflows.
3) SWF may throttle you if you make a large amount of calls in a short period of time (and I've seen it happen), but the doc is not clear on what large means and what the period of time is. See: http://docs.aws.amazon.com/amazonswf/latest/developerguide/swf-dg-limits.html

I don't think it is going to complete. The parent workflow exits when all tasks including activities and child workflows are completed or failed. Internally workflow is invoked inside a TryCatchFinally and completes only when doFinally is executed. It doesn't depend on child workflow returning any result as well as its child policy. Even if it returns void the generated workflow client still returns Promise<Void> and ignoring this promise is not going to change the behavior. It should be pretty straightforward to add workflowClient.detach method to disconnect parent from the child. It would complete ExternalTask that controls the child workflow completion .

IMHO I wouldn't bother with detaching the clients as in this case any errors from them would be ignored. Keeping them attached ensures that parent gets exception if child fails for any reason.

As far as starting rate I wouldn't be very concerned. The more important limitation is the number of children that a single parent can have. Due to need to return the whole workflow history on every decision having too many children is not a good idea. I wouldn't recommend more than 100. If you need more, create a tree of workflows. Parent with 100 children each of them creating their own 100 children gives 10k children.

Starting an independent workflow from an activity using generated external client is a possible workaround. Just make sure that possible failure conditions like workflow starting and then activity failing due to communication error are handled correctly. Use ActivityExecutionContext to access reference to the SWF endpoint and other related information.

It seems like you are interested in starting external workflows and not child workflows. Best practice would be to start the workflows from an activity in the parent workflow. That way there is no hierarchy created. Also when starting the workflows and activities from decision worker the rate is controlled ( from what I remember it is 10 activites and 4 child workflows per second, it can be increased by talking to swf team). Some spikes are allowed but if the rate does not go down then you would start getting rateexceededexception ( not throughput or throttle). However no such issue if you start it from an activity which then is equivalent to just starting new workflows.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM