예제 #1
0
        public void HeartBeat()
        {
            SetLastWorkTime();

            if (_thread != null && _thread.ThreadState != ThreadState.Stopped)
            {
                return;
            }

            List <OptionBase> options = _optionFinder.Find(DatabaseWorker);

            EstimatedOptionCount = options.Count;

            if (options.Count == 0 && _isDoomed == false)
            {
                return;
            }

            if (_isDoomed)
            {
                StopThread();

                return;
            }

            OptionBase currentOption = _optionDecider.Decide(options);

            _thread = new Thread(RunThread);

            _thread.Start(currentOption);
        }
예제 #2
0
        public void RunThread(object currentOptionObject)
        {
            OptionBase currentOption = (OptionBase)currentOptionObject;

            _optionStatus.BeginOption(currentOption, DatabaseWorker);

            OptionReport report = new OptionReport(currentOption.GetType());

            try
            {
                currentOption.ExecuteOption(report);

                _optionDecider.DelayOptionFromFails(currentOption);

                currentOption.DatabaseOption?.Execute(_mongoConnection);
            }
            catch (Exception exception)
            {
                Log.Write(_mongoConnection, exception.Message, typeof(ThreadHolder), exception.StackTrace, Config.LogLevelEnum.HeartError);

                _optionDecider.DelayOptionFromFails(currentOption);

                currentOption.DatabaseOption?.ExecuteFail(_mongoConnection);
            }
            finally
            {
                report.FinishReport();

                report.WriteLog(_mongoConnection);

                _optionStatus.EndOption(currentOption, report);
            }
        }