Open rbennettcw opened 2 weeks ago
RetryStrategy
and enforced with the withRetryStrategy
wrapper util function// reusable strategy which retries on network failure
const networkFailStrategy = new RetryStrategy({
'Network request failure': {
maxRetries: 3,
condition: async (err) => {
const networkErrors = [
'ECONNREFUSED', 'ETIMEDOUT', 'EHOSTUNREACH', 'ENETDOWN'
];
return networkErrors.includes(error.code);
},
}
});
// multiple strategies can be applied like middleware
const result = await withRetryStrategy([networkFailStrategy], async () => {
return contractHelpers.doThingThatThrows();
});
// any errors that aren't caught by retry policy = Block
// key = human readable error message, value = retry options
type RetryOptions = Record<string, {
maxRetries: number;
condition: (Error) => Promise<boolean>;
}>;
liking it đź’Ż ... let's discuss soon
Updating the pattern to allow mapping any error to any strategy for future-proofing (exact naming convention TBD):
const networkFailStrategy = new Strategy({
'Network request failure': {
fn: async (err) => {
const networkErrors = [
'ECONNREFUSED', 'ETIMEDOUT', 'EHOSTUNREACH', 'ENETDOWN'
];
if (networkErrors.includes(error.code)) {
return new RetryStrategy({ maxRetries: 3 })
}
return null
},
}
});
Next steps:
When policies or projections throw errors, they may need to be retried since they are not directly invoked by an actor.
Acceptance Criteria