Beispiel #1
0
        private void ProcessGeneralEvents(CancellationToken token)
        {
            Log.Debug("GeneralEvent task - started");
            SleepTimeWrapper sleepTimeWrapper = SleepTimeWrapper.Create();

            while (!token.IsCancellationRequested)
            {
                try
                {
                    if (!_generalEventsQueue.IsEmpty())
                    {
                        IList <CiEvent> snapshot = _generalEventsQueue.GetSnapshot();
                        EnrichEvents(snapshot);
                        _octaneApis.SendEvents(snapshot);

                        //post-send treating
                        foreach (CiEvent ciEvent in snapshot)
                        {
                            //1.Log
                            Log.Debug($"Build {ciEvent.BuildInfo} - {ciEvent.EventType.ToString().ToUpper()} event is sent");

                            //2.Clear original list
                            _generalEventsQueue.Remove(ciEvent);
                        }
                    }
                    sleepTimeWrapper.SleepTime = SleepTimeWrapper.DEFAULT_SLEEP_TIME;
                }
                catch (Exception e)
                {
                    ExceptionHelper.HandleExceptionAndRestartIfRequired(e, Log, "ProcessGeneralEvents");

                    sleepTimeWrapper.SleepTime = sleepTimeWrapper.SleepTime * 2;
                    if (sleepTimeWrapper.SleepTime > SleepTimeWrapper.MAX_SLEEP_TIME)
                    {
                        _generalEventsQueue.Clear();
                        Log.Error($"Impossible to handle general events. Event queue is cleared.");
                        sleepTimeWrapper.SleepTime = SleepTimeWrapper.DEFAULT_SLEEP_TIME;
                    }
                }

                Thread.Sleep(sleepTimeWrapper.SleepTime * 1000);//wait before next loop
            }
            Log.Debug("GeneralEvents task - finished");
        }
Beispiel #2
0
        private static void ProcessFinishEvents(CancellationToken token, EventsQueue queue, string queueName, Action <CiEvent> action, SleepTimeWrapper sleepTimeWrapper)
        {
            Log.Debug($"{queueName} task - started");
            while (!token.IsCancellationRequested)
            {
                try
                {
                    while (!queue.IsEmpty())
                    {
                        var ciEvent = queue.Peek();

                        action(ciEvent);

                        //remove item from _finishedEventsQueue
                        queue.Dequeue();
                        sleepTimeWrapper.SleepTime = SleepTimeWrapper.DEFAULT_SLEEP_TIME;
                    }
                }
                catch (Exception e)
                {
                    ExceptionHelper.HandleExceptionAndRestartIfRequired(e, Log, "ProcessFinishEvents");

                    sleepTimeWrapper.SleepTime = sleepTimeWrapper.SleepTime * 2;
                    if (sleepTimeWrapper.SleepTime > SleepTimeWrapper.MAX_SLEEP_TIME)
                    {
                        CiEvent ciEvent = queue.Dequeue();
                        Log.Error($"Build {ciEvent.BuildInfo} - Impossible to handle event in {queueName} queue. Event is removed from queue.");
                        sleepTimeWrapper.SleepTime = SleepTimeWrapper.DEFAULT_SLEEP_TIME;
                    }
                }

                Thread.Sleep(sleepTimeWrapper.SleepTime * 1000);//wait before next loop
            }
            Log.Debug($"{queueName} task - finished");
        }
Beispiel #3
0
        public void Start()
        {
            _generalEventsQueue = PluginManager.GetInstance().GeneralEventsQueue;
            _scmEventsQueue     = PluginManager.GetInstance().ScmEventsQueue;
            _testResultsQueue   = PluginManager.GetInstance().TestResultsQueue;

            _generalEventsThread = Task.Factory.StartNew(() => ProcessGeneralEvents(_cancellationToken.Token), TaskCreationOptions.LongRunning);
            _scmEventsThread     = Task.Factory.StartNew(() => ProcessFinishEvents(_cancellationToken.Token, _scmEventsQueue, "ScmEvents", SendScmEvent, SleepTimeWrapper.Create()), TaskCreationOptions.LongRunning);
            _testResultsThread   = Task.Factory.StartNew(() => ProcessFinishEvents(_cancellationToken.Token, _testResultsQueue, "TestResults", SendTestResults, SleepTimeWrapper.Create()), TaskCreationOptions.LongRunning);
            Log.Debug("QueuesManager - started");
        }