示例#1
0
        public async Task <ServiceStatus> GetCurrentStatusAsync()
        {
            var serviceStatus = new ServiceStatus {
                Name = ServiceName, Status = ServiceState.Red, CheckCorrelationId = Guid.NewGuid()
            };
            var checkSubject = "maths";

            try
            {
                var request   = MessageConverter.GetCourseListInput(checkSubject);
                var apiResult = await serviceHelper.UseAsync <ServiceInterface, CourseListOutput>(async x => await tolerancePolicy.ExecuteAsync(() => x.CourseListAsync(request), Constants.CourseSearchEndpointConfigName, FaultToleranceType.CircuitBreaker), Constants.CourseSearchEndpointConfigName);

                //The call worked ok
                serviceStatus.Status = ServiceState.Amber;

                //We have actual data
                if (apiResult.CourseListResponse.CourseDetails.Any())
                {
                    serviceStatus.Status             = ServiceState.Green;
                    serviceStatus.CheckCorrelationId = Guid.Empty;
                }
                else
                {
                    applicationLogger.Warn($"{nameof(CourseSearchService)}.{nameof(GetCurrentStatusAsync)} : {Constants.ServiceStatusWarnLogMessage} - Correlation Id [{serviceStatus.CheckCorrelationId}] - Searched for [{checkSubject}]");
                }
            }
            catch (Exception ex)
            {
                applicationLogger.ErrorJustLogIt($"{nameof(CourseSearchService)}.{nameof(GetCurrentStatusAsync)} : {Constants.ServiceStatusFailedLogMessage} - Correlation Id [{serviceStatus.CheckCorrelationId}] - Searched for [{checkSubject}]", ex);
            }

            return(serviceStatus);
        }
        public async Task <CourseDetails> GetCourseDetailsAsync(string courseId, string oppurtunityId)
        {
            var result = await tolerancePolicy.ExecuteAsync(async() => await apiService.GetCourseDetailsAsync(courseId, oppurtunityId).ConfigureAwait(false), Constants.CourseSearchEndpointConfigName, FaultToleranceType.CircuitBreaker).ConfigureAwait(false);

            return(mapper.Map <CourseDetails>(result));
        }
 public async Task <HttpResponseMessage> GetAsync(string requestUri, FaultToleranceType toleranceType = FaultToleranceType.RetryWithCircuitBreaker)
 {
     return(await policy.ExecuteAsync(() => httpClient.GetAsync(new Uri(requestUri)), response => !response.IsSuccessStatusCode, $"{typeof(TService).Name}-{nameof(GetAsync)}", toleranceType));
 }
        public async Task <ServiceStatus> GetCurrentStatusAsync()
        {
            var serviceStatus = new ServiceStatus {
                Name = ServiceName, Status = ServiceState.Red, Notes = string.Empty
            };

            var checkSubject = "maths";

            serviceStatus.CheckParametersUsed = $"Searched for - {checkSubject}";

            try
            {
                var request   = MessageConverter.GetCourseListInput(checkSubject);
                var apiResult = await serviceHelper.UseAsync <ServiceInterface, CourseListOutput>(async x => await tolerancePolicy.ExecuteAsync(() => x.CourseListAsync(request), Constants.CourseSearchEndpointConfigName, FaultToleranceType.CircuitBreaker), Constants.CourseSearchEndpointConfigName);

                //The call worked ok
                serviceStatus.Status = ServiceState.Amber;
                serviceStatus.Notes  = "Success Response";

                //We have actual data
                if (apiResult.CourseListResponse.CourseDetails.Any())
                {
                    serviceStatus.Status = ServiceState.Green;
                    serviceStatus.Notes  = string.Empty;
                }
            }
            catch (Exception ex)
            {
                serviceStatus.Notes = $"{Constants.ServiceStatusFailedCheckLogsMessage} - {applicationLogger.LogExceptionWithActivityId(Constants.ServiceStatusFailedLogMessage, ex)}";
            }

            return(serviceStatus);
        }
 public async Task EnsureIndexAsync(string indexName)
 {
     var definition = GetIndexDefenition(indexName);
     await policy.ExecuteAsync(() => searchClient.Indexes.CreateOrUpdateAsync(definition), nameof(AzSearchService <T>), FaultToleranceType.RetryWithCircuitBreaker);
 }