Currently my code makes a series of updates to some resource via a REST API but I also have some "rollback" logic that basically updates the resource to its original state before my updates if some kind of error happened. So in psuedo-code, the logic looks like:
public void doUpdate(Resource r) {
// do a GET to get the latest eTag
// make PUT call with eTag to do actual update
}
public void myLogic(Resource r) {
Resource original = r;
Resource copy = r.copy();
try {
doUpdate(copy);
// do something to copy
doUpdate(copy);
// do some more things to copy
doUpdate(copy)
} catch (Exception e) {
// rollback to original version
doUpdate(original);
}
}
This is a simplification of my actual code but my question is: Is it more correct to do GET before every update to get the latest eTag(as shown) or should I get the eTag once at the beginning and then "chain" the eTag I get from the prior update for the next update, including the rollback step?