If a workflow has many childworkflow and each childworkflow has multiple activities with different MaximumAttempts set then how can we know whether all the MaximumAttempts has been reached by the parent workflow.
My usecase is to send a notification on workflow failure but currently if MaximumAttempts is N then the method is getting called N times. I want to get a control where i can call my notification on failure only when getMaximumAttempts has been reached by Parent.
We need to trigger some notification if my workflow fails but as each child has n number of setMaximumAttempts so we are not able to fetch information whether the max re attempts has been reached or not as we want to send notification only after all the re attempts has been exhausted. Some thing like this : Workflow.getInfo().getAttempt()) but is there any mthod which can tell whether all the reattempts has been reached.
We need to trigger some notification if my workflow fails but as each child has n number of setMaximumAttempts so we are not able to fetch information whether the max re attempts has been reached
A workflow gets an ActivityFailure exception only when all the attempts are exhausted. So if it catches the exception and sends a notification before rethrowing it to fail the workflow it would solve your problem.
My use case is something like this :: ParentWorkFlow has multiple ChildWorkFlow with multiple activities which has some setMaximumAttempts .
Now if something fails in Child, we have to send notification only when all the reTry attempts has been exhausted . so i am looking for any API which can inform whether the maxAttempt has been reached so that we can trigger our action only once after all the retry.
As I said the moment the max activity retries is exhausted the workflow is going to get an ActivityFailure exception which it can handle according to your business logic.
if i understand your intentions is you want some kind of action to be taken up when a workflow fails (notification), but dont want the notification for all intermintent failues but only when the workflow fails permanently (activity/workflow do not get resubmitted etc)
so, if workflow 1 spaws workflow 2 and workflow 3, and workflow 2 fails, (workflow 1 could actually spawn wf2 again as continue as new )… so its for workflow 1 to determine when to send notification or not.
if you are reusing the workflows (say workflow 2) is independent workflow but gets embedded in workflow 1 as well, then you can always use workflow.parent kind of api to figure out if workflow 2 needs to send notification or, should it let workflow 1 manage the notification…
so net net, in your scenario the parent process/workflow should manage the notification… sub workflows should mute them self up when managed through a parent…
so i am thinking of something like this
Workflow2 {
execute(){
//last step is to send notification
if(workflow.parent ==null) //indedpent workflow
{
/notify
}
}
}
workflow1 {
execute() {
childworflow2.execute();
//notifiy
if(wf.parent ==null)
{
//notifiy
}
}
}
so , my proposal is check workflow.parent before notification, and if parent is null send notification, if its not null , let parent determine what to do…
just like you handle exception , if there is no catch block, it will get rolled up to parent…
Want to share my exploration which i am getting which is totally different from what you have mentioned i.e activityFailure Exception is occurring multiple times based on the retry option i have set.
I have a workflow which has an activity having maximum attemp as 2 like setRetryOptions(RetryOptions.newBuilder().setMaximumAttempts(2)