Class RetryUtil
Utilities for retries.
Inherited Members
Namespace: Cognite.Extractor.Common
Assembly: Cognite.Common.dll
Syntax
public static class RetryUtil
Methods
| Edit this page View SourceRetryAsync(string, Action, RetryUtilConfig, Func<Exception, bool>, ILogger, CancellationToken)
Retry the given method based on config.
Declaration
public static Task RetryAsync(string name, Action generator, RetryUtilConfig config, Func<Exception, bool> shouldRetry, ILogger logger, CancellationToken token)
Parameters
| Type | Name | Description |
|---|---|---|
| string | name | Name of the task being retried, for logging. |
| Action | generator | Method called once per retry. |
| RetryUtilConfig | config | Retry config |
| Func<Exception, bool> | shouldRetry | A method returning true if the method should continue after the given exception was thrown. |
| ILogger | logger | Logger logging information about retries. |
| CancellationToken | token | Cancellation token |
Returns
| Type | Description |
|---|---|
| Task |
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException |
RetryAsync(string, Action, RetryUtilConfig, CancellationToken)
Retry the given method based on config.
Declaration
public static Task RetryAsync(string name, Action generator, RetryUtilConfig config, CancellationToken token)
Parameters
| Type | Name | Description |
|---|---|---|
| string | name | Name of the task being retried, for logging. |
| Action | generator | Method called once per retry. |
| RetryUtilConfig | config | Retry config |
| CancellationToken | token | Cancellation token |
Returns
| Type | Description |
|---|---|
| Task |
RetryAsync(string, Func<Task>, RetryUtilConfig, Func<Exception, bool>, ILogger, CancellationToken)
Retry the given method based on config.
Declaration
public static Task RetryAsync(string name, Func<Task> generator, RetryUtilConfig config, Func<Exception, bool> shouldRetry, ILogger logger, CancellationToken token)
Parameters
| Type | Name | Description |
|---|---|---|
| string | name | Name of the task being retried, for logging. |
| Func<Task> | generator | Method returning a task, called once per retry. |
| RetryUtilConfig | config | Retry config |
| Func<Exception, bool> | shouldRetry | A method returning true if the method should continue after the given exception was thrown. |
| ILogger | logger | Logger logging information about retries. |
| CancellationToken | token | Cancellation token |
Returns
| Type | Description |
|---|---|
| Task |
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException |
RetryAsync(string, Func<Task>, RetryUtilConfig, CancellationToken)
Retry the given method based on config.
Declaration
public static Task RetryAsync(string name, Func<Task> generator, RetryUtilConfig config, CancellationToken token)
Parameters
| Type | Name | Description |
|---|---|---|
| string | name | Name of the task being retried, for logging. |
| Func<Task> | generator | Method returning a task, called once per retry. |
| RetryUtilConfig | config | Retry config |
| CancellationToken | token | Cancellation token |
Returns
| Type | Description |
|---|---|
| Task |
RetryResultAsync<T>(string, Func<Task<T>>, RetryUtilConfig, Func<Exception, bool>, ILogger, CancellationToken)
Retry the given method based on config, return a result of type T.
Declaration
public static Task<T> RetryResultAsync<T>(string name, Func<Task<T>> generator, RetryUtilConfig config, Func<Exception, bool> shouldRetry, ILogger logger, CancellationToken token)
Parameters
| Type | Name | Description |
|---|---|---|
| string | name | Name of the task being retried, for logging. |
| Func<Task<T>> | generator | Method returning a task, called once per retry. |
| RetryUtilConfig | config | Retry config |
| Func<Exception, bool> | shouldRetry | A method returning true if the method should continue after the given exception was thrown. |
| ILogger | logger | Logger logging information about retries. |
| CancellationToken | token | Cancellation token |
Returns
| Type | Description |
|---|---|
| Task<T> |
Type Parameters
| Name | Description |
|---|---|
| T |
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException |
RetryResultAsync<T>(string, Func<Task<T>>, RetryUtilConfig, CancellationToken)
Retry the given method based on config, return a result of type T.
Declaration
public static Task<T> RetryResultAsync<T>(string name, Func<Task<T>> generator, RetryUtilConfig config, CancellationToken token)
Parameters
| Type | Name | Description |
|---|---|---|
| string | name | Name of the task being retried, for logging. |
| Func<Task<T>> | generator | Method returning a task, called once per retry. |
| RetryUtilConfig | config | Retry config |
| CancellationToken | token | Cancellation token |
Returns
| Type | Description |
|---|---|
| Task<T> |
Type Parameters
| Name | Description |
|---|---|
| T |
RetryResultAsync<T>(string, Func<T>, RetryUtilConfig, Func<Exception, bool>, ILogger, CancellationToken)
Retry the given method based on config, return a result of type T.
Declaration
public static Task<T> RetryResultAsync<T>(string name, Func<T> generator, RetryUtilConfig config, Func<Exception, bool> shouldRetry, ILogger logger, CancellationToken token)
Parameters
| Type | Name | Description |
|---|---|---|
| string | name | Name of the task being retried, for logging. |
| Func<T> | generator | Method called once per retry. |
| RetryUtilConfig | config | Retry config |
| Func<Exception, bool> | shouldRetry | A method returning true if the method should continue after the given exception was thrown. |
| ILogger | logger | Logger logging information about retries. |
| CancellationToken | token | Cancellation token |
Returns
| Type | Description |
|---|---|
| Task<T> |
Type Parameters
| Name | Description |
|---|---|
| T |
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException |
RetryResultAsync<T>(string, Func<T>, RetryUtilConfig, CancellationToken)
Retry the given method based on config, return a result of type T.
Declaration
public static Task<T> RetryResultAsync<T>(string name, Func<T> generator, RetryUtilConfig config, CancellationToken token)
Parameters
| Type | Name | Description |
|---|---|---|
| string | name | Name of the task being retried, for logging. |
| Func<T> | generator | Method called once per retry. |
| RetryUtilConfig | config | Retry config |
| CancellationToken | token | Cancellation token |
Returns
| Type | Description |
|---|---|
| Task<T> |
Type Parameters
| Name | Description |
|---|---|
| T |
RetryUntilAsync<T>(string, Func<Task<T>>, RetryUtilConfig, Func<Exception, bool>, Func<T, bool>, ILogger, CancellationToken)
Like RetryResultAsync<T>(string, Func<Task<T>>, RetryUtilConfig, Func<Exception, bool>, ILogger, CancellationToken),
but for calls that signal "not ready yet" by returning an incomplete result rather
than throwing (e.g. a read that comes back empty for a just-written resource). A
result rejected by isDone is retried the same way an exception
accepted by shouldRetry is. Once attempts are exhausted, the
last-seen result is returned rather than an exception being thrown, so the caller's
own check on the result produces the actual failure.
Declaration
public static Task<T> RetryUntilAsync<T>(string name, Func<Task<T>> generator, RetryUtilConfig config, Func<Exception, bool> shouldRetry, Func<T, bool> isDone, ILogger logger, CancellationToken token)
Parameters
| Type | Name | Description |
|---|---|---|
| string | name | Name of the task being retried, for logging. |
| Func<Task<T>> | generator | Method returning a task, called once per retry. |
| RetryUtilConfig | config | Retry config |
| Func<Exception, bool> | shouldRetry | A method returning true if the method should continue after the given exception was thrown. |
| Func<T, bool> | isDone | A method returning true if a successful result is acceptable. |
| ILogger | logger | Logger logging information about retries. |
| CancellationToken | token | Cancellation token |
Returns
| Type | Description |
|---|---|
| Task<T> |
Type Parameters
| Name | Description |
|---|---|
| T |
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException |
RetryUntilAsync<T>(string, Func<Task<T>>, RetryUtilConfig, Func<T, bool>, CancellationToken)
Like RetryUntilAsync<T>(string, Func<Task<T>>, RetryUtilConfig, Func<Exception, bool>, Func<T, bool>, ILogger, CancellationToken), retrying on any exception except cancellation.
Declaration
public static Task<T> RetryUntilAsync<T>(string name, Func<Task<T>> generator, RetryUtilConfig config, Func<T, bool> isDone, CancellationToken token)
Parameters
| Type | Name | Description |
|---|---|---|
| string | name | |
| Func<Task<T>> | generator | |
| RetryUtilConfig | config | |
| Func<T, bool> | isDone | |
| CancellationToken | token |
Returns
| Type | Description |
|---|---|
| Task<T> |
Type Parameters
| Name | Description |
|---|---|
| T |