コード例 #1
0
        private IndexMeta getIndexMeta()
        {
            // TODO: all this needs cleaning.
            var(index, aliased) = findOrCreateIndex(Name);

            if (!AppSettings.IsRebuild && !aliased)
            {
                updateAlias(Name, index);
            }

            // look for any existing resume data.
            var indexMeta = IndexMeta.GetByName(index) ?? new IndexMeta
            {
                Alias = Name,
                Name  = index,
            };

            indexMeta.LastId = ResumeFrom ?? indexMeta.LastId;

            if (AppSettings.IsRebuild)
            {
                // Save the position the score processing queue should be reset to if rebuilding an index.
                // If there is already an existing value, the processor is probabaly resuming from a previous run,
                // so we likely want to preserve that value.
                if (!indexMeta.ResetQueueTo.HasValue)
                {
                    var mode = HighScore.GetRulesetId <T>();
                    indexMeta.ResetQueueTo = ScoreProcessQueue.GetLastProcessedQueueId(mode);
                }
            }
            else
            {
                if (string.IsNullOrWhiteSpace(indexMeta.Schema))
                {
                    throw new Exception("FATAL ERROR: attempting to process queue without a known version.");
                }

                if (indexMeta.Schema != AppSettings.Schema)
                {
                    // A switchover is probably happening, so signal that this mode should be skipped.
                    throw new VersionMismatchException($"`{Name}` found version {indexMeta.Schema}, expecting {AppSettings.Schema}");
                }

                // process queue reset if any.
                if (indexMeta.ResetQueueTo.HasValue)
                {
                    Console.WriteLine($"Resetting queue_id > {indexMeta.ResetQueueTo}");
                    ScoreProcessQueue.UnCompleteQueued <T>(indexMeta.ResetQueueTo.Value);
                    indexMeta.ResetQueueTo = null;
                }
            }

            indexMeta.UpdatedAt = DateTimeOffset.UtcNow;
            IndexMeta.UpdateAsync(indexMeta);
            IndexMeta.Refresh();

            return(indexMeta);
        }
コード例 #2
0
        public void Run()
        {
            var index = findOrCreateIndex(Name);
            // find out if we should be resuming
            var resumeFrom = ResumeFrom ?? IndexMeta.GetByName(index)?.LastId;

            Console.WriteLine();
            Console.WriteLine($"{typeof(T)}, index `{index}`, chunkSize `{AppSettings.ChunkSize}`, resume `{resumeFrom}`");
            Console.WriteLine();

            var indexCompletedArgs = new IndexCompletedArgs
            {
                Alias     = Name,
                Index     = index,
                StartedAt = DateTime.Now
            };

            dispatcher = new BulkIndexingDispatcher <T>(Name, index);

            try
            {
                var readerTask = databaseReaderTask(resumeFrom);
                dispatcher.Run();
                readerTask.Wait();

                indexCompletedArgs.Count       = readerTask.Result;
                indexCompletedArgs.CompletedAt = DateTime.Now;

                updateAlias(Name, index);
                IndexCompleted(this, indexCompletedArgs);
            }
            catch (AggregateException ae)
            {
                ae.Handle(handleAggregateException);
            }

            // Local function exception handler.
            bool handleAggregateException(Exception ex)
            {
                if (!(ex is InvalidOperationException))
                {
                    return(false);
                }

                Console.WriteLine(ex.Message);
                return(true);
            }
        }