Sending notification when the workflow has failed

Hi Team,
a help here…
My requirement is to send a notification when the workflow has failed.

Workflow can be consider as failed when:

  1. there is a terminal exception
  2. workflow has gone through maximum number of retries.

Also, I want to make sure that I have sent the notification in case of failure.

I got to know that if we get an ActivityFailure in workflow then that means that the activity has failed and it can be due to both of these reasons:

  1. there is a terminal exception
  2. workflow has gone through maximum number of retries.
    So that would solve the issue.

So I can handle it like:

try {
    // code that gives non retriable exception/ terminal exception
} catch (ActivityException ex) {
    try {
        myActivity.sendNotification(param);
    } catch(ActivityException ex) {
        log.error("Not able to send failure notification");
    }
}

Why are you retrying workflows? This is not recommended in the majority of situations.

Sorry my bad. I should have meant: when activity has gone through max number of retries.

So, I just want to invoke another activity of sending notification. Is there a better way to achieve the same?

Then, your code is the way to go. Write an interceptor that encapsulates this logic to make this reusable across many activities.

1 Like