예제 #1
0
        public Task <IEnumerable <TrainingDetail> > GetAllFrameworkDetailsAsync()
        {
            var retry = PollyRetryPolicies.GetFixedIntervalPolicy((exception, time, retryCount, context) =>
            {
                _logger.Warn($"Error retrieving framework details from FrameworkApi: ({exception.Message}). Retrying... attempt {retryCount}");
            });

            return(retry.ExecuteAsync(InternalGetFrameworkDetailsAsync));
        }
예제 #2
0
        public Task <Framework> GetFrameworkDetailsAsync(int code)
        {
            var retry = PollyRetryPolicies.GetFixedIntervalPolicy((exception, time, retryCount, context) =>
            {
                _logger.Warn($"Error retrieving framework details from TrainingDetailService: ({exception.Message}). Retrying... attempt {retryCount}");
            });

            return(retry.ExecuteAsync(() => InternalGetFrameworkDetailsAsync(code)));
        }
예제 #3
0
        public Task <Standard> GetStandardDetailsAsync(int code)
        {
            var retry = PollyRetryPolicies.GetFixedIntervalPolicy((exception, time, retryCount, context) =>
            {
                _logger.Warn($"Error retrieving standard details from Apprenticeship Api: ({exception.Message}). Retrying... attempt {retryCount}");
            });

            return(retry.ExecuteAsync(() => InternalGetStandardDetailsAsync(code)));
        }
예제 #4
0
        public Task <IEnumerable <TrainingDetail> > GetAllStandardDetailsAsync()
        {
            var retry = PollyRetryPolicies.GetFixedIntervalPolicy((exception, time, retryCount, context) =>
            {
                _logger.Warn($"Error retrieving list of standards from Apprenticeship Api: ({exception.Message}). Retrying... attempt {retryCount}");
            });

            return(retry.ExecuteAsync(InternalGetAllStandardDetailsAsync));
        }
예제 #5
0
        public Task <SearchApprenticeshipVacanciesResponse> SearchApprenticeshipVacanciesAsync(
            VacancySearchParameters parameters)
        {
            var retry = PollyRetryPolicies.GetFixedIntervalPolicy((exception, time, retryCount, context) =>
            {
                _logger.Warn($"Error searching for apprenticeships in search index: ({exception.Message}). Retrying... attempt {retryCount}");
            });

            return(retry.ExecuteAsync(() => InternalSearchApprenticeshipVacanciesAsync(parameters)));
        }
        public async Task <T> ExecuteWithRetryAsync <T>(string operationName, Func <SqlConnection, Task <T> > asyncFunc)
        {
            var retry = PollyRetryPolicies.GetFixedIntervalPolicy((exception, time, retryCount, context) =>
            {
                _logger.Warn($"Database operation {operationName} failed with error: ({exception.Message}). Retrying... attempt {retryCount}");
            });

            var result = await retry.ExecuteAsync(async() =>
            {
                using (var conn = GetConnection())
                {
                    await conn.OpenAsync().ConfigureAwait(false);

                    return(await asyncFunc(conn).ConfigureAwait(false));
                }
            }).ConfigureAwait(false);

            return(result);
        }
예제 #7
0
        public void ThenReturnFixedIntervalPolicy()
        {
            var message = "error";
            var retries = new List <Tuple <string, TimeSpan, int> >();

            var policy = PollyRetryPolicies.GetFixedIntervalPolicy((exception, timeSpan, retryCount, context) =>
            {
                retries.Add(new Tuple <string, TimeSpan, int>(exception.Message, timeSpan, retryCount));
            });

            Func <Task> act = async() =>
            {
                await policy.ExecuteAsync(() =>
                {
                    message += "x";
                    throw new Exception(message);
                });
            };

            //Should throw the 4th exception
            act.ShouldThrow <Exception>().WithMessage("errorxxxx");

            //Should retry 3 times with a 500ms pause between retries.
            //see https://docs.microsoft.com/en-us/azure/architecture/best-practices/retry-service-specific#sql-database-using-adonet-retry-guidelines
            retries[0].Item1.Should().Be("errorx");
            retries[0].Item2.Should().Be(TimeSpan.FromMilliseconds(500));
            retries[0].Item3.Should().Be(1);

            retries[1].Item1.Should().Be("errorxx");
            retries[1].Item2.Should().Be(TimeSpan.FromMilliseconds(500));
            retries[1].Item3.Should().Be(2);

            retries[2].Item1.Should().Be("errorxxx");
            retries[2].Item2.Should().Be(TimeSpan.FromMilliseconds(500));
            retries[2].Item3.Should().Be(3);
        }