Add fluent interface for retrying actions
RetryHelper accumulated a lot of functionality and using it was not
straight-forward for callers. Clean-up the class and add fluent
interface for calling actions with retry:
Object result = retryHelper.changeUpdate(
"myActionName",
batchUpdateFactory -> {
try (BatchUpdate bu = newBatchUpdate(batchUpdateFactory)) {
...
}
return result;
})
.retryOn(LockFailureException.class::isInstance)
...
.call();
With the fluent interface providing an action name is now mandatory
which makes the retry metrics more useful.
Signed-off-by: Edwin Kempin <ekempin@google.com>
Change-Id: Iecdfa5b153ab17f31c8ec1d2dca82b428fcf5800
This commit is contained in:
@@ -79,11 +79,14 @@ public class ChangeCleanupRunner implements Runnable {
|
||||
// abandonInactiveOpenChanges skips failures instead of throwing, so retrying will never
|
||||
// actually happen. For the purposes of this class that is fine: they'll get tried again the
|
||||
// next time the scheduled task is run.
|
||||
retryHelper.execute(
|
||||
updateFactory -> {
|
||||
abandonUtil.abandonInactiveOpenChanges(updateFactory);
|
||||
return null;
|
||||
});
|
||||
retryHelper
|
||||
.changeUpdate(
|
||||
"abandonInactiveOpenChanges",
|
||||
updateFactory -> {
|
||||
abandonUtil.abandonInactiveOpenChanges(updateFactory);
|
||||
return null;
|
||||
})
|
||||
.call();
|
||||
} catch (RestApiException | UpdateException e) {
|
||||
logger.atSevere().withCause(e).log("Failed to cleanup changes.");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user