protected void WaitForFinish(RebuildStatus status, Int32 timeoutInSeconds = 5)
        {
            DateTime startWait = DateTime.Now;

            while (status.BucketActiveCount > 0 && DateTime.Now.Subtract(startWait).TotalSeconds < timeoutInSeconds)
            {
                Thread.Sleep(100);
            }
            Assert.That(status.BucketActiveCount, Is.EqualTo(0), "Rebuild stuck");
        }
Example #2
0
        /// <summary>
        /// Gets the rebuild status.
        /// </summary>
        /// <returns>
        /// The <see cref="HttpResponseMessage"/>.
        /// </returns>
        public HttpResponseMessage GetRebuildStatus()
        {
            var model = new RebuildStatus
            {
                IsProcessing   = NexuContext.Current.IsProcessing,
                ItemsProcessed = NexuContext.Current.ItemsProcessed,
                ItemName       = NexuContext.Current.ItemInProgress
            };

            return(this.Request.CreateResponse(HttpStatusCode.OK, model));
        }
        public Guid RebuildIndex(string uniqueName)
        {
            var site   = GetKnownSites().FirstOrDefault(s => s.UniqueName == uniqueName);
            var guid   = Guid.NewGuid();
            var status = new RebuildStatus {
                UniqueName = uniqueName
            };

            _rebuilds[guid] = status;

            if (site != null)
            {
                var baseUri = new Uri(Request.RequestUri, "/");

                HostingEnvironment.QueueBackgroundWorkItem(token =>
                {
                    try
                    {
                        if (site is IPublisherSearchConfig psc)
                        {
                            RebuildRemoteSite(psc, token);
                        }
                        else
                        {
                            RebuildLocalSite(baseUri, site, token);
                        }

                        status.Success = true;
                    }
                    catch (Exception ex)
                    {
                        var err = Guid.NewGuid();
                        Logger.Error <ExternalSiteSearchController>(ex, "Could not rebuild index - Error ID: {err}", err);
                        status.Error = $"An error occurred; search the logs for error ID {err} for more details.  " + ex.Message;
                    }
                    finally
                    {
                        status.Complete = true;
                    }
                });
            }
            else
            {
                status.Complete = true;
                status.Error    = "Unknown Site";
            }

            return(guid);
        }
Example #4
0
        public async Task event_is_dispatched()
        {
            await CreateAggregate().ConfigureAwait(false);

            ConcurrentCheckpointTracker thisTracker = new ConcurrentCheckpointTracker(_db, 60);

            thisTracker.SetUp(new[] { _projection1, _projection3 }, 1, false);
            await thisTracker.UpdateSlotAndSetCheckpointAsync(_projection1.Info.SlotName, new[] { _projection1.Info.CommonName }, 1, true);

            await thisTracker.UpdateSlotAndSetCheckpointAsync(_projection3.Info.SlotName, new[] { _projection3.Info.CommonName }, 1, true);

            RebuildStatus status = await sut.RebuildAsync().ConfigureAwait(false);

            WaitForFinish(status);
            var coll      = _db.GetCollection <BsonDocument>("Sample");
            var allRecord = coll.FindAll().ToList();

            Assert.That(allRecord, Has.Count.EqualTo(1));
        }
Example #5
0
        public void Start()
        {
            if (Status == RebuildStatus.Running)
            {
                return;
            }

            lock (_statusLock)
            {
                if (Status == RebuildStatus.Running)
                {
                    return;
                }

                Status = RebuildStatus.Running;
                new Thread(ThreadStart).Start();
            }
        }
Example #6
0
        private void DoWork(CommerceInstance instance)
        {
            IndexStore store = null;

            try
            {
                var rebuildDirectory = IndexStores.GetDirectory(Context.Instance, Context.Culture, Context.ModelType, true);
                var liveDirectory = IndexStores.GetDirectory(Context.Instance, Context.Culture, Context.ModelType, false);

                // Ensure temp folder are deleted (last rebuild might encounter errors when deleting the temp folder)
                Kooboo.IO.IOUtility.DeleteDirectory(rebuildDirectory, true);
                Kooboo.IO.IOUtility.DeleteDirectory(liveDirectory + "-tmp", true);

                var total = _source.Count(instance, Context.Culture);
                var totalRebuilt = 0;

                Progress = 0;

                store = new IndexStore(Context.ModelType, FSDirectory.Open(rebuildDirectory), Analyzers.GetAnalyzer(Context.Culture));

                foreach (var data in _source.Enumerate(instance, Context.Culture))
                {
                    if (_cancelling)
                    {
                        break;
                    }

                    store.Index(data);

                    totalRebuilt++;
                    Progress = (int)Math.Round(totalRebuilt * 100 / (double)total);
                }

                if (_cancelling)
                {
                    store.Dispose();

                    UpdateTaskInfo(info =>
                    {
                        info.ClearError();
                        info.LastRebuildStatus = RebuildStatus.Cancelled;
                    });

                    _cancelling = false;
                    _cancelledEvent.Set();

                    Status = RebuildStatus.Cancelled;
                }
                else
                {
                    store.Commit();
                    store.Dispose();

                    UpdateTaskInfo(info =>
                    {
                        info.ClearError();
                        info.LastRebuildStatus = RebuildStatus.Success;
                        info.LastSucceededRebuildTimeUtc = DateTime.UtcNow;
                    });

                    // Replace old index files with the new ones

                    IndexStores.Close(Context.Instance, Context.Culture, Context.ModelType);

                    var liveDirectoryExists = System.IO.Directory.Exists(liveDirectory);
                    if (liveDirectoryExists)
                    {
                        System.IO.Directory.Move(liveDirectory, liveDirectory + "-tmp");
                        Kooboo.IO.IOUtility.DeleteDirectory(liveDirectory, true);
                    }

                    System.IO.Directory.Move(rebuildDirectory, liveDirectory);

                    if (liveDirectoryExists)
                    {
                        Kooboo.IO.IOUtility.DeleteDirectory(liveDirectory + "-tmp", true);
                    }

                    Status = RebuildStatus.Success;
                }

                Progress = 0;
            }
            catch (Exception ex)
            {
                if (store != null)
                {
                    store.Dispose();
                }

                UpdateTaskInfo(info =>
                {
                    info.LastRebuildStatus = RebuildStatus.Failed;
                    info.LastRebuildError = ex.Message;
                    info.LastRebuildErrorDetail = ex.StackTrace;
                });

                Status = RebuildStatus.Failed;
            }
        }