예제 #1
0
        public async Task CreateScheduledIndex(DateTime scheduledRefreshDateTime)
        {
            NlogCorrelationId.SetJobCorrelationId(_name, true);

            Log.Info($"Creating new scheduled {_name}");
            var stopwatch = Stopwatch.StartNew();

            var newIndexName = IndexerHelper.GetIndexNameAndDateExtension(scheduledRefreshDateTime, _indexSettings.IndexesAlias);

            var indexProperlyCreated = _indexerHelper.CreateIndex(newIndexName);

            if (!indexProperlyCreated)
            {
                throw new Exception($"{_name} index not created properly, exiting...");
            }

            Log.Info($"Indexing documents for {_name}.");

            var result = await _indexerHelper.IndexEntries(newIndexName).ConfigureAwait(false);

            if (result.IsSuccessful)
            {
                _indexerHelper.ChangeUnderlyingIndexForAlias(newIndexName);

                Log.Debug("Swap completed...");

                _indexerHelper.DeleteOldIndexes(scheduledRefreshDateTime);
            }

            stopwatch.Stop();
            var properties = new Dictionary <string, object>
            {
                { "Alias", _indexSettings.IndexesAlias },
                { "ExecutionTime", stopwatch.ElapsedMilliseconds },
                { "IndexCorrectlyCreated", result.IsSuccessful },
                { "TotalCount", result.TotalCount }
            };

            Log.Debug($"Created {_name}", properties);
        }
        public void CheckRoatpAndCreateIndexAndUpdateAlias(DateTime scheduledRefreshDateTime)
        {
            Stopwatch stopwatch = Stopwatch.StartNew();

            _log.Debug("Checking for updates to ROATP");

            var roatpProviders = _indexerHelper.LoadEntries();

            if (roatpProviders != null)
            {
                var providers = roatpProviders.ToList();

                var infoHasChanged = _indexerHelper.HasRoatpInfoChanged(providers);

                if (infoHasChanged)
                {
                    _log.Debug($"Update to ROATP spreadsheet detected");

                    var newIndexName         = IndexerHelper.GetIndexNameAndDateExtension(scheduledRefreshDateTime, _indexSettings.IndexesAlias);
                    var indexProperlyCreated = _indexerHelper.CreateIndex(newIndexName);

                    if (!indexProperlyCreated)
                    {
                        throw new Exception($"{_name} index not created properly, exiting...");
                    }

                    try
                    {
                        _indexerHelper.IndexEntries(newIndexName, providers);

                        CheckIfIndexHasBeenCreated(newIndexName, providers.Count);

                        var stats = _indexerHelper.SendEvents(newIndexName);

                        _indexerHelper.ChangeUnderlyingIndexForAlias(newIndexName);

                        _log.Debug("Swap completed...");

                        stopwatch.Stop();
                        var properties = new Dictionary <string, object> {
                            { "Alias", _indexSettings.IndexesAlias }, { "ExecutionTime", stopwatch.ElapsedMilliseconds }
                        };
                        _log.Debug($"Created {_name}", properties);
                        _log.Debug($"{_name}ing complete.");

                        if (stats.TotalCount == 0)
                        {
                            _log.Info("Successfully made changes to existing providers");
                        }
                        else
                        {
                            _log.Info("Successfully updated and added new providers", new Dictionary <string, object> {
                                { "TotalCount", stats.TotalCount }
                            });
                        }
                        _monitoringService.SendMonitoringNotification();
                    }
                    catch (Exception ex)
                    {
                        _log.Error(ex, ex.Message);
                    }
                }
                else
                {
                    _log.Info("Successfully checked for changes");
                    _monitoringService.SendMonitoringNotification();
                }
            }
        }