The issue was because this code was only called for a successfull execution in the rules. So we added this piece of code in the finally block so it now gets called for all failed and successfull calls.

But we are still facing the same issue on a clustered environment. Any suggestions on why it is not working on a clustered environment.