pub trait RetryPolicy<Config, Params, CandidOutput, Output> {
// Required methods
fn retry(
&mut self,
request: &mut Request<Config, Params, CandidOutput, Output>,
result: &mut Result<Output, IcError>,
) -> Option<Request<Config, Params, CandidOutput, Output>>;
fn clone_request(
&mut self,
request: &Request<Config, Params, CandidOutput, Output>,
) -> Option<Request<Config, Params, CandidOutput, Output>>;
}Expand description
Defines how and when requests made by EvmRpcClient should be retried.
A retry policy decides whether a failed request should be retried, and if so, it can modify the request or the result before the next attempt. This allows for flexible strategies such as adding more cycles, or adjusting parameters based on previous failures.
Required Methods§
Sourcefn retry(
&mut self,
request: &mut Request<Config, Params, CandidOutput, Output>,
result: &mut Result<Output, IcError>,
) -> Option<Request<Config, Params, CandidOutput, Output>>
fn retry( &mut self, request: &mut Request<Config, Params, CandidOutput, Output>, result: &mut Result<Output, IcError>, ) -> Option<Request<Config, Params, CandidOutput, Output>>
Called after a request fails to decide whether it should be retried.
If the policy decides to retry, it returns the (potentially mutated) request
that will be sent again.
Returning None means no further retries should be attempted.
This method may mutate:
- the request, for example to add cycles, change parameters, or adjust the expected response size.
- the result, for example to record retry information or attach metadata.
- the policy itself, if it is stateful, e.g., keeping count of the number of attempts.
Because the policy may be stateful, it should generally be cloned before the first call to
RetryPolicy::retry if it will be reused.
Sourcefn clone_request(
&mut self,
request: &Request<Config, Params, CandidOutput, Output>,
) -> Option<Request<Config, Params, CandidOutput, Output>>
fn clone_request( &mut self, request: &Request<Config, Params, CandidOutput, Output>, ) -> Option<Request<Config, Params, CandidOutput, Output>>
Optionally clones a request before sending it.
The result of this method will be passed to RetryPolicy::retry in case of failure.
If it returns None, no retries will be performed.