/// <summary> /// <see cref="IDocumentService.GetDocument(string)(string)"/> /// </summary> /// <param name="identifier">Document with field <c>resoruceID</c>.</param> /// <param name="searchIndex">The index from which the document should be fetched.</param> public object GetDocument(string identifier, UpdateIndex searchIndex) { if (string.IsNullOrWhiteSpace(identifier)) { throw new ArgumentNullException(nameof(identifier), "The identifier must not be null or empty."); } var documentIdentifier = HttpUtility.UrlEncode(identifier); //Delete document with the unique identifer. return(_elasticSearchRepository.GetDocument(documentIdentifier, searchIndex)); }
public async void ReindexingSwitch(string pidUriString) { if (_reindexingSwitch) { _logger.LogInformation($"Reindexing switch is true for non local env and thus we wait before switching index"); var document = (JObject)JsonConvert.DeserializeObject(pidUriString); var lastPidUris = document["lastPidUris"]; bool continueCheck = true; DateTime loopStart = DateTime.Now; _logger.LogInformation($"Checking if the piduris have been received in new index at {loopStart} hours", loopStart); int myCount = 0; while (continueCheck && DateTime.Now.Subtract(loopStart).Hours < 4) { myCount++; _logger.LogInformation($"The loop is running for {myCount} time", myCount); lastPidUris.ToList().ForEach(pidUri => { try { var response = _elasticSearchRepository.GetDocument(HttpUtility.UrlEncode(pidUri.ToString()), UpdateIndex.Published); if (response != null && continueCheck) { _logger.LogInformation($"Document present {pidUri} in new index", pidUri); continueCheck = false; } } catch (System.Exception ex) { if (ex is EntityNotFoundException) { _logger.LogWarning(ex, $"Document not recieved yet in new index for {pidUri} by message queue", pidUri.ToString()); } } }); await Task.Delay(600000); } _logger.LogInformation($"Loop finished. Switching Search Aliases at {DateTime.Now} hours"); SwitchAndDeleteOldIndex(); } }