Пример #1
0
 public void Start(JobQueue queue, bool alwaysRunning)
 {
     var processor = new JobProcessor(config, currentDb, manager, indexUpdater, indexReader);
     var running = true;
     while (running)
     {
         var curSize = queue.Size();
         while (curSize > 0)
         {
             var loop = 0;
             while (loop < curSize)
             {
                 try
                 {
                     processor.Add(queue.Dequeue());
                 }
                 catch (Exception ex)
                 {
                     log.ErrorException("Dequeue Exception", ex);
                 }
                 loop++;
             }
             curSize = queue.Size();
         }
         processor.Flush(true);
         running = Wait(queue, alwaysRunning, processor.ProcessCount);
     }
 }
Пример #2
0
        bool Wait(JobQueue queue, bool alwaysRunning, long processCount)
        {
            var ret = false;
            var exitMethod = false;
            var dtCountdown = DateTime.UtcNow + TimeSpan.FromSeconds(30);
            var sw = new SpinWait();
            if (traceEnabled && Waiting != null)
            {
                Waiting(this, new WaitEventArgs(processCount, queue.ID));
            }

            while (!exitMethod)
            {
                var localStopping = stopping;
                // Exit if Timeout and not always running
                // Or Signaled from Manager to stop job
                if ((!alwaysRunning && dtCountdown > DateTime.UtcNow) || (localStopping == 1))
                {
                    exitMethod = true;
                }
                else
                {
                    // Something in queue to process
                    if (queue.Size() > 0)
                    {
                        ret = true;
                        exitMethod = true;
                    }
                    else
                    {
                        sw.SpinOnce();
                    }
                }
            }
            return ret;
        }
Пример #3
0
 void InitializeQueues()
 {
     int queueSize;
     if (!Int32.TryParse(config.GetSetting(SettingKeys.Manager_QueueSize), out queueSize))
     {
         queueSize = 1024;
     }
     whenToStartNewTask = Math.Min((int)(queueSize * 0.5), 50);
     for (int i = 0; i < queues.Length; i++)
     {
         queues[i] = new JobQueue(queueSize, traceEnabled);
     }
 }