dimanche 27 février 2022

How to organize a series of code to handle rollback mechanism gracefully? [closed]

I have a strange logic with rollback mechanism like:

A ------------> B ------> C ------> D
   |error        |error
   |             |
Rollback A<----Rollback B

The code now isn't very satisfied with me like:

try:
  A()
except ExceptionA:
  RollbackA()
try:
  B()
except ExceptionB:
  RollbackB()
  RollbackA()
C()
D()

Can anyone help me to optimize it? Sorry for confusing every one, what I concern is I want to optimize it with a graceful framework or design pattern. Current code hasn't any problem. However, If I have many steps to rollback, it will become complicated and redundant.

Aucun commentaire:

Enregistrer un commentaire