Esempio n. 1
0
        private bool ExecuteTasks()
        {
            bool foundWork = false;

            transactionalStorage.Batch(actions =>
            {
                Task task = GetApplicableTask(actions);
                if (task == null)
                {
                    return;
                }

                context.UpdateFoundWork();

                Log.Debug("Executing {0}", task);
                foundWork = true;

                context.CancellationToken.ThrowIfCancellationRequested();

                try
                {
                    task.Execute(context);
                }
                catch (Exception e)
                {
                    Log.WarnException(
                        string.Format("Task {0} has failed and was deleted without completing any work", task),
                        e);
                }
            });
            return(foundWork);
        }
Esempio n. 2
0
        protected bool ExecuteIndexing(bool isIdle, out bool onlyFoundIdleWork)
        {
            var indexesToWorkOn        = new List <IndexToWorkOn>();
            var localFoundOnlyIdleWork = new Reference <bool> {
                Value = true
            };

            transactionalStorage.Batch(actions =>
            {
                foreach (var indexesStat in actions.Indexing.GetIndexesStats().Where(IsValidIndex))
                {
                    var failureRate = actions.Indexing.GetFailureRate(indexesStat.Id);
                    if (failureRate.IsInvalidIndex)
                    {
                        if (Log.IsDebugEnabled)
                        {
                            Log.Debug("Skipped indexing documents for index: {0} because failure rate is too high: {1}",
                                      indexesStat.Id,
                                      failureRate.FailureRate);
                        }
                        continue;
                    }
                    if (IsIndexStale(indexesStat, actions, isIdle, localFoundOnlyIdleWork) == false)
                    {
                        continue;
                    }
                    var index = context.IndexStorage.GetIndexInstance(indexesStat.Id);
                    if (index == null) // not there
                    {
                        continue;
                    }

                    if (ShouldSkipIndex(index))
                    {
                        continue;
                    }

                    if (context.IndexDefinitionStorage.GetViewGenerator(indexesStat.Id) == null)
                    {
                        continue; // an index that is in the process of being added, ignoring it, we'll check again on the next run
                    }
                    var indexToWorkOn   = GetIndexToWorkOn(indexesStat);
                    indexToWorkOn.Index = index;

                    indexesToWorkOn.Add(indexToWorkOn);
                }
            });

            UpdateStalenessMetrics(indexesToWorkOn.Count);

            onlyFoundIdleWork = localFoundOnlyIdleWork.Value;
            if (indexesToWorkOn.Count == 0)
            {
                return(false);
            }


            context.UpdateFoundWork();
            context.CancellationToken.ThrowIfCancellationRequested();

            using (context.IndexDefinitionStorage.CurrentlyIndexing())
            {
                ExecuteIndexingWork(indexesToWorkOn);
            }

            indexReplacer.ReplaceIndexes(indexesToWorkOn.Select(x => x.IndexId).ToList());

            return(true);
        }