WaitForWork() public method

public WaitForWork ( TimeSpan timeout, int &workerWorkCounter ) : bool
timeout TimeSpan
workerWorkCounter int
return bool
Esempio n. 1
0
 public void Execute()
 {
     while (context.DoWork)
     {
         var foundWork = false;
         try
         {
             foundWork = ExecuteTasks();
         }
         catch (Exception e)
         {
             log.ErrorException("Failed to execute indexing", e);
         }
         if (foundWork == false)
         {
             context.WaitForWork(TimeSpan.FromHours(1), ref workCounter, FlushIndexesOnIdle);
         }
     }
 }
Esempio n. 2
0
        public void Execute()
        {
            while (context.DoWork)
            {
                var  foundWork = false;
                Task task      = null;
                try
                {
                    int tasks = 0;
                    transactionalStorage.Batch(actions =>
                    {
                        task = actions.Tasks.GetMergedTask(out tasks);
                        if (task == null)
                        {
                            return;
                        }

                        log.DebugFormat("Executing {0}", task);
                        foundWork = true;

                        try
                        {
                            task.Execute(context);
                        }
                        catch (Exception e)
                        {
                            log.WarnFormat(e, "Task {0} has failed and was deleted without completing any work", task);
                        }
                    });
                    context.PerformanceCounters.IncrementProcessedTask(tasks);
                }
                catch (Exception e)
                {
                    log.Error("Failed to execute task: " + task, e);
                }
                if (foundWork == false)
                {
                    context.WaitForWork(TimeSpan.FromSeconds(1));
                }
            }
        }
Esempio n. 3
0
        public void Execute()
        {
            using (LogContext.WithDatabase(context.DatabaseName))
            {
                Init();
                var  name        = GetType().Name;
                var  workComment = "WORK BY " + name;
                bool isIdle      = false;
                while (context.RunIndexing)
                {
                    bool foundWork;
                    try
                    {
                        bool onlyFoundIdleWork;
                        foundWork = ExecuteIndexing(isIdle, out onlyFoundIdleWork);
                        if (foundWork && onlyFoundIdleWork == false)
                        {
                            isIdle = false;
                        }

                        while (context.RunIndexing) // we want to drain all of the pending tasks before the next run
                        {
                            if (ExecuteTasks() == false)
                            {
                                break;
                            }
                            foundWork = true;
                        }
                    }
                    catch (OutOfMemoryException oome)
                    {
                        foundWork = true;
                        HandleOutOfMemoryException(oome);
                    }
                    catch (AggregateException ae)
                    {
                        foundWork = true;
                        var actual = ae.ExtractSingleInnerException();
                        var oome   = actual as OutOfMemoryException;
                        if (oome == null)
                        {
                            if (IsEsentOutOfMemory(actual))
                            {
                                autoTuner.OutOfMemoryExceptionHappened();
                            }
                            Log.ErrorException("Failed to execute indexing", ae);
                        }
                        else
                        {
                            HandleOutOfMemoryException(oome);
                        }
                    }
                    catch (OperationCanceledException)
                    {
                        Log.Info("Got rude cancellation of indexing as a result of shutdown, aborting current indexing run");
                        return;
                    }
                    catch (Exception e)
                    {
                        foundWork = true; // we want to keep on trying, anyway, not wait for the timeout or more work
                        Log.ErrorException("Failed to execute indexing", e);
                        if (IsEsentOutOfMemory(e))
                        {
                            autoTuner.OutOfMemoryExceptionHappened();
                        }
                    }
                    if (foundWork == false && context.RunIndexing)
                    {
                        isIdle = context.WaitForWork(context.Configuration.TimeToWaitBeforeRunningIdleIndexes, ref workCounter, () =>
                        {
                            try
                            {
                                FlushIndexes();
                            }
                            catch (Exception e)
                            {
                                Log.WarnException("Could not flush indexes properly", e);
                            }
                        }, name);
                    }
                    else // notify the tasks executer that it has work to do
                    {
                        context.ShouldNotifyAboutWork(() => workComment);
                        context.NotifyAboutWork();
                    }
                }
                Dispose();
            }
        }
Esempio n. 4
0
 public void Execute()
 {
     using (new DisposableAction(() => LogContext.DatabaseName.Value = null))
     {
         LogContext.DatabaseName.Value = context.DatabaseName;
         var name        = GetType().Name;
         var workComment = "WORK BY " + name;
         while (context.DoWork)
         {
             var foundWork = false;
             try
             {
                 foundWork = ExecuteIndexing();
                 while (context.DoWork)                         // we want to drain all of the pending tasks before the next run
                 {
                     if (ExecuteTasks() == false)
                     {
                         break;
                     }
                     foundWork = true;
                 }
             }
             catch (OutOfMemoryException oome)
             {
                 foundWork = true;
                 HandleOutOfMemoryException(oome);
             }
             catch (AggregateException ae)
             {
                 foundWork = true;
                 var oome = ae.ExtractSingleInnerException() as OutOfMemoryException;
                 if (oome == null)
                 {
                     log.ErrorException("Failed to execute indexing", ae);
                 }
                 else
                 {
                     HandleOutOfMemoryException(oome);
                 }
             }
             catch (OperationCanceledException)
             {
                 log.Info("Got rude cancelation of indexing as a result of shutdown, aborting current indexing run");
                 return;
             }
             catch (Exception e)
             {
                 foundWork = true;                         // we want to keep on trying, anyway, not wait for the timeout or more work
                 log.ErrorException("Failed to execute indexing", e);
             }
             if (foundWork == false)
             {
                 context.WaitForWork(TimeSpan.FromHours(1), ref workCounter, FlushIndexes, name);
             }
             else                     // notify the tasks executer that it has work to do
             {
                 context.ShouldNotifyAboutWork(() => workComment);
                 context.NotifyAboutWork();
             }
         }
     }
 }
Esempio n. 5
0
        public void Execute()
        {
            using (LogContext.WithDatabase(context.DatabaseName))
            {
                Init();

                var name        = GetType().Name;
                var workComment = "WORK BY " + name;

                bool isIdle = false;
                while (ShouldRun)
                {
                    bool foundWork;
                    try
                    {
                        bool onlyFoundIdleWork;
                        foundWork = ExecuteIndexing(isIdle, out onlyFoundIdleWork);
                        if (foundWork && onlyFoundIdleWork == false)
                        {
                            isIdle = false;
                        }

                        var foundTasksWork = ExecuteTasks();
                        foundWork = foundWork || foundTasksWork;
                    }
                    catch (OutOfMemoryException oome)
                    {
                        foundWork = true;
                        HandleOutOfMemoryException(oome);
                    }
                    catch (AggregateException ae)
                    {
                        foundWork = true;
                        var actual = ae.ExtractSingleInnerException();
                        var oome   = actual as OutOfMemoryException;
                        if (oome == null)
                        {
                            if (TransactionalStorageHelper.IsOutOfMemoryException(actual))
                            {
                                autoTuner.HandleOutOfMemory();
                            }
                            Log.ErrorException("Failed to execute indexing", ae);
                        }
                        else
                        {
                            HandleOutOfMemoryException(oome);
                        }
                    }
                    catch (OperationCanceledException)
                    {
                        Log.Info("Got rude cancellation of indexing as a result of shutdown, aborting current indexing run");
                        return;
                    }
                    catch (Exception e)
                    {
                        foundWork = true; // we want to keep on trying, anyway, not wait for the timeout or more work
                        Log.ErrorException("Failed to execute indexing", e);
                        if (TransactionalStorageHelper.IsOutOfMemoryException(e))
                        {
                            autoTuner.HandleOutOfMemory();
                        }
                    }
                    if (foundWork == false && ShouldRun)
                    {
                        isIdle = context.WaitForWork(context.Configuration.Indexing.TimeToWaitBeforeRunningIdleIndexes.AsTimeSpan, ref workCounter, () =>
                        {
                            try
                            {
                                FlushIndexes();
                            }
                            catch (Exception e)
                            {
                                Log.WarnException("Could not flush indexes properly", e);
                            }

                            try
                            {
                                CleanupPrefetchers();
                            }
                            catch (Exception e)
                            {
                                Log.WarnException("Could not cleanup prefetchers properly", e);
                            }

                            try
                            {
                                CleanupScheduledReductions();
                            }
                            catch (Exception e)
                            {
                                Log.WarnException("Could not cleanup scheduled reductions properly", e);
                            }
                        }, name);
                    }
                    else // notify the tasks executer that it has work to do
                    {
                        context.ShouldNotifyAboutWork(() => workComment);
                        context.NotifyAboutWork();
                    }
                }
                Dispose();
            }
        }
        public void Execute()
        {
            using (LogContext.WithResource(context.DatabaseName))
            {
                Init();

                var name        = GetType().Name;
                var workComment = "WORK BY " + name;

                bool isIdle = false;
                while (ShouldRun)
                {
                    bool foundWork;
                    try
                    {
                        bool onlyFoundIdleWork;
                        foundWork = ExecuteIndexing(isIdle, out onlyFoundIdleWork);
                        if (foundWork && onlyFoundIdleWork == false)
                        {
                            isIdle = false;
                        }

                        var foundTasksWork = ExecuteTasks();
                        foundWork = foundWork || foundTasksWork;
                    }
                    catch (OutOfMemoryException oome)
                    {
                        foundWork = true;
                        HandleSystemOutOfMemoryException(oome);
                    }
                    catch (OperationCanceledException)
                    {
                        Log.Info("Got rude cancellation of indexing, aborting current indexing run");
                        continue;
                    }
                    catch (AggregateException ae)
                    {
                        if (IsOperationCanceledException(ae))
                        {
                            Log.Info("Got rude cancellation of indexing, aborting current indexing run");
                            continue;
                        }

                        foundWork = true;
                        if (HandleIfOutOfMemory(ae, null) == false)
                        {
                            Log.ErrorException("Failed to execute indexing", ae);
                        }
                    }
                    catch (Exception e)
                    {
                        foundWork = true; // we want to keep on trying, anyway, not wait for the timeout or more work
                        if (HandleIfOutOfMemory(e, null) == false)
                        {
                            Log.ErrorException("Failed to execute indexing", e);
                        }
                    }
                    if (foundWork == false && ShouldRun)
                    {
                        isIdle = context.WaitForWork(context.Configuration.TimeToWaitBeforeRunningIdleIndexes, ref workCounter, () =>
                        {
                            try
                            {
                                FlushIndexes();
                            }
                            catch (Exception e)
                            {
                                Log.WarnException("Could not flush indexes properly", e);
                            }

                            try
                            {
                                CleanupPrefetchers();
                            }
                            catch (Exception e)
                            {
                                Log.WarnException("Could not cleanup prefetchers properly", e);
                            }

                            try
                            {
                                CleanupScheduledReductions();
                            }
                            catch (Exception e)
                            {
                                Log.WarnException("Could not cleanup scheduled reductions properly", e);
                            }
                        }, name);
                    }
                    else // notify the tasks executer that it has work to do
                    {
                        context.ShouldNotifyAboutWork(() => workComment);
                        context.NotifyAboutWork();
                    }
                }
                Dispose();
            }
        }