/// <summary> /// Gets all the search request in `Ready for Search` status /// </summary> /// <param name="cancellationToken"></param> /// <returns></returns> public async Task <IEnumerable <SSG_SearchApiRequest> > GetAllReadyForSearchAsync( CancellationToken cancellationToken) { int readyForSearchCode = SearchApiRequestStatusReason.ReadyForSearch.Value; List <SSG_SearchApiRequest> results = new List <SSG_SearchApiRequest>(); //todo: we need to change to use following code, but ODataClient 4 has problems with expand, curent implemented code is a workaround //ref: https://powerusers.microsoft.com/t5/Power-Apps-Ideas/Web-API-Implement-expand-on-collections/idi-p/221291 IEnumerable <SSG_SearchApiRequest> searchApiRequests = await _oDataClient.For <SSG_SearchApiRequest>() .Select(x => x.SearchApiRequestId) .Filter(x => x.StatusCode == readyForSearchCode) .FindEntriesAsync(cancellationToken); foreach (SSG_SearchApiRequest request in searchApiRequests) { SSG_SearchApiRequest searchApiRequest = await _oDataClient.For <SSG_SearchApiRequest>() .Key(request.SearchApiRequestId) .Expand(x => x.Identifiers) .Expand(x => x.DataProviders) .Expand(x => x.SearchRequest) .FindEntryAsync(cancellationToken); results.Add(searchApiRequest); } return(results); }
private static void UpdateProviderInfo(List <SSG_DataProvider> providers, SSG_SearchApiRequest searchApiRequest, string availableDataPartners) { if (searchApiRequest.DataProviders != null) { List <string> dataPartner; if (!string.IsNullOrEmpty(availableDataPartners)) { dataPartner = availableDataPartners.Split(new char[] { ':' }).ToList(); } else { dataPartner = providers.Select(x => x.AdaptorName).ToList(); } List <SSG_SearchapiRequestDataProvider> apiProviders = new List <SSG_SearchapiRequestDataProvider>(); foreach (SSG_SearchapiRequestDataProvider prov in searchApiRequest.DataProviders) { /// get a list of data partner in prod - appsettings /// if provider not in list, do not add to apiProviders if (dataPartner.Any(dataPartner => dataPartner == prov.AdaptorName)) { var provider = providers.FirstOrDefault(x => x.AdaptorName == prov.AdaptorName); if (provider != null) { prov.NumberOfRetries = provider.NumberOfRetries; prov.TimeBetweenRetries = provider.TimeBetweenRetries; prov.SearchSpeed = provider.SearchSpeed; } apiProviders.Add(prov); } } searchApiRequest.DataProviders = apiProviders.ToArray(); } }
private static void FilterAffectedDataProvider(SSG_DataProvider provider, SSG_SearchApiRequest searchApiRequest) { List <SSG_SearchapiRequestDataProvider> ssgApiDataProviders = new List <SSG_SearchapiRequestDataProvider>(); ssgApiDataProviders.AddRange(searchApiRequest.DataProviders); var list = ssgApiDataProviders.FindAll(x => x.AdaptorName == provider.AdaptorName); list.ForEach(x => x.TimeBetweenRetries = provider.TimeBetweenRetries); list.ForEach(x => x.NumberOfRetries = provider.NumberOfRetries); searchApiRequest.DataProviders = list.ToArray(); }
private static void UpdateProviderInfo(List <SSG_DataProvider> providers, SSG_SearchApiRequest searchApiRequest) { if (searchApiRequest.DataProviders != null) { List <SSG_SearchapiRequestDataProvider> apiProviders = new List <SSG_SearchapiRequestDataProvider>(); foreach (SSG_SearchapiRequestDataProvider prov in searchApiRequest.DataProviders) { var provider = providers.FirstOrDefault(x => x.AdaptorName == prov.AdaptorName); if (provider != null) { prov.NumberOfRetries = provider.NumberOfRetries; prov.TimeBetweenRetries = provider.TimeBetweenRetries; prov.SearchSpeed = provider.SearchSpeed; } apiProviders.Add(prov); } searchApiRequest.DataProviders = apiProviders.ToArray(); } }
/// <summary> /// Get all failed search request that has not exceeded the number of days to retry /// </summary> /// <param name="cancellationToken"></param> /// <returns></returns> public async Task <IEnumerable <SSG_SearchApiRequest> > GetAllValidFailedSearchRequest(CancellationToken cancellationToken, SSG_DataProvider[] dataProviders) { List <SSG_SearchApiRequest> results = new List <SSG_SearchApiRequest>(); //todo: we need to change to use following code, but ODataClient 4 has problems with expand, curent implemented code is a workaround //ref: https://powerusers.microsoft.com/t5/Power-Apps-Ideas/Web-API-Implement-expand-on-collections/idi-p/221291 foreach (SSG_DataProvider provider in dataProviders) { string adaptorName = provider.AdaptorName; int noOfDaysToRetry = provider.NumberOfDaysToRetry; int allRetryDone = NullableBooleanType.No.Value; IEnumerable <SSG_SearchapiRequestDataProvider> searchApiRequests = await _oDataClient.For <SSG_SearchapiRequestDataProvider>() .Select(x => x.SearchAPIRequestId) .Filter(x => x.NumberOfFailures > 0) .Filter(x => x.AdaptorName == adaptorName) .Filter(x => x.NumberOfFailures < noOfDaysToRetry) .Filter(x => x.AllRetriesDone == allRetryDone) .FindEntriesAsync(cancellationToken); foreach (SSG_SearchapiRequestDataProvider request in searchApiRequests) { SSG_SearchApiRequest searchApiRequest = await _oDataClient.For <SSG_SearchApiRequest>() .Key(request.SearchAPIRequestId) .Expand(x => x.Identifiers) .Expand(x => x.DataProviders) .Expand(x => x.SearchRequest) .FindEntryAsync(cancellationToken); FilterAffectedDataProvider(provider, searchApiRequest); searchApiRequest.IsFailed = true; results.Add(searchApiRequest); } } return(results); }