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
        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");
        }