// polly retry
pollyRetry_ExecuteAndCapture(
work, retryCount, delayer,
handlesException, handlesResult):
pollyResult = new
for i = 0, i <= retryCount, i++:
// default if success or ends in exception
pollyResult.finalHandledResult = default
pollyResult.finalException = default
pollyResult.faultType = default
pollyResult.exceptionType = default
if i > 0:
delay(delayer(i))
try:
result = work()
if handlesResult(result):
pollyResult.outcome = outcome.failure
pollyResult.faultType = faultType.handledResult
pollyResult.finalHandledResult = result
// retry
continue
else:
pollyResult.outcome = outcome.successful
pollyResult.result = result
break
catch ex:
pollyResult.finalException = ex
if handlesException(ex):
pollyResult.outcome = outcome.failure
pollyResult.faultType = faultType.handledException
pollyResult.exceptionType = exceptionType.handled
// swallow, retry
continue
else:
// do not throw
pollyResult.outcome = outcome.failure
pollyResult.faultType = faultType.unhandledException
pollyResult.exceptionType = exceptionType.unhandled
break
return pollyResult
// polly retry
pollyRetry_Execute(
work, retryCount, delayer,
handlesException, handlesResult):
pollyResult = pollyRetry_ExecuteAndCapture(work, retryCount, delayer,
handlesException, handlesResult)
if pollyResult.finalException != null:
throw pollyResult.finalException
return pollyResult.result
No comments:
Post a Comment