Hi,
I have several async parallel activities which wait for some external signals to complete the activities the implementation is like below. I understand that I can call CompleteActivity once receiving the signal. But my requirement is that as long as one signal arrives, I will complete all activities.
for _, branch := range s.Branches {
f := executeAsync(...)
selector.AddFuture(f, func(f workflow.Future) {
var r interface{}
err := f.Get(ctx, &r)
resp = append(resp, r)
})
}
for i := 0; i < len(s.Branches); i++ {
selector.Select(ctx)
}
Is there a nicer way to support this scenario instead of call CompleteActivity multiple times once receive a signal?
Can you clarify your question a bit more? I don’t see any signals or “CompleteActivity”. There is no “CompleteActivity” call you can make from inside a workflow.
I didnt mean I call CompleteActivity from inside of workflow, I basically have an event handler consumes the signal and call CompleteActivity. But I want to finish all activities when the first event arrives.
Sorry, I am still not following. Signal handlers run inside the workflow. What is “CompleteActivity”? Maybe you can give a larger snippet showing what you are doing?
Are you asking if there’s an easier way to wait for all futures to complete?
Signal handlers are not running inside the workflow. The signal here is an external signal from rabbitmq.
Parallel Async Activity1
Parallel Async Activity2
when my service consume the rabbitmq event, it will call CompleteActivityById to complete the above activities.
I want to complete both activity once an event arrive, I understand that I can call CompleteActivity twice to complete those two activities, but it does not look good. I was wondering if there is a nicer way to do that
There are possibly some other approaches such as using a common activity to do multiple things or using a workflow to cancel the activities instead of completing them. But those of course aren’t the exact same thing.
I would recommend not using async activities, but signals to notify completion of external operations. If we know more about your use case end to end we could give a better recommendation.