public void WaitAndRetryAsync_Retries_On_Exception() { var retryInvoked = false; _pollyRetryService.WaitAndRetryAsync <Exception, object> ( 3, i => TimeSpan.FromSeconds(1), () => retryInvoked = true, () => throw new Exception("What") ); Assert.True(retryInvoked); }
public void WaitAndRetryAsync_Retries_On_Exception() { var retryInvoked = false; _pollyRetryService.WaitAndRetryAsync <Exception, object> ( 3, i => TimeSpan.FromMilliseconds(1), retryAttempt => retryInvoked = true, #pragma warning disable S3626 // Jump statements should not be redundant () => throw new Exception("What") #pragma warning restore S3626 // Jump statements should not be redundant ); Assert.True(retryInvoked); }
private async Task <bool> BookKinlyMeetingRoomWithRetriesAsync(Guid conferenceId, bool audioRecordingRequired, string ingestUrl, IEnumerable <EndpointDto> endpoints) { var result = await _pollyRetryService.WaitAndRetryAsync <Exception, bool> ( 3, _ => TimeSpan.FromSeconds(10), retryAttempt => _logger.LogWarning($"Failed to BookKinlyMeetingRoomAsync. Retrying attempt {retryAttempt}"), callResult => !callResult, () => BookKinlyMeetingRoomAsync(conferenceId, audioRecordingRequired, ingestUrl, endpoints) ); return(result); }
public async Task <ConferenceDetailsResponse> GetConferenceDetailsByHearingIdWithRetry(Guid hearingId, string errorMessage) { try { var details = await _pollyRetryService.WaitAndRetryAsync <VideoApiException, ConferenceDetailsResponse> ( 6, _ => TimeSpan.FromSeconds(8), retryAttempt => _logger.LogWarning( "Failed to retrieve conference details from the VideoAPi for hearingId {Hearing}. Retrying attempt {RetryAttempt}", hearingId, retryAttempt), videoApiResponseObject => !videoApiResponseObject.HasValidMeetingRoom(), () => _videoApiClient.GetConferenceByHearingRefIdAsync(hearingId, false) ); return(details); } catch (VideoApiException ex) { _logger.LogError(ex, $"{errorMessage}: {ex.Message}"); } return(new ConferenceDetailsResponse()); }
public async Task <EmailNotificationResponse> SendEmailAsyncRetry(string contactEmail, string notifyTemplateId, Dictionary <string, dynamic> requestParameters, string notificationId) { var maxRetryAttempts = 2; var pauseBetweenFailures = TimeSpan.FromSeconds(5); var result = await _pollyRetryService.WaitAndRetryAsync <Exception, EmailNotificationResponse> ( maxRetryAttempts, _ => pauseBetweenFailures, retryAttempt => _logger.LogWarning( "Failed to send email to send email to the NotifyAPi for notifcationId {Hearing}. Retrying attempt {RetryAttempt}", notificationId, retryAttempt ), callResult => callResult == null, () => _asyncNotificationClient.SendEmailAsync(contactEmail, notifyTemplateId, requestParameters, notificationId) ); return(result); }
public async Task <TestCallResult> GetTestCallScoreAsync(Guid participantId, int retryAttempts = 2) { var maxRetryAttempts = retryAttempts; var pauseBetweenFailures = TimeSpan.FromSeconds(5); var result = await _pollyRetryService.WaitAndRetryAsync <Exception, TestCallResult> ( maxRetryAttempts, _ => pauseBetweenFailures, retryAttempt => _logger.LogWarning( "Failed to retrieve test score for participant {ParticipantId} at {KinlySelfTestApiUrl}. Retrying attempt {retryAttempt}", participantId, _kinlyConfigOptions.KinlySelfTestApiUrl, retryAttempt), callResult => callResult == null, () => _kinlySelfTestHttpClient.GetTestCallScoreAsync(participantId) ); return(result); }
public async Task <IActionResult> GetTestCallResultForParticipant(Guid participantId) { try { var score = await _pollyRetryService.WaitAndRetryAsync <NotFoundException, TestCallResult> ( 2, x => TimeSpan.FromSeconds(Math.Pow(1, x)), null, () => _kinlyPlatformService.GetTestCallScoreAsync(participantId) ); return(Ok(score)); } catch (Exception ex) { const string key = "participantId"; ApplicationLogger.TraceException(TraceCategories.MissingResource, "Missing test score for participant", ex, User, new Dictionary <string, string> { { key, participantId.ToString() } }); return(NotFound($"No test score result found for participant Id: {participantId}")); } }