Exemple #1
0
        private void ExecuteProcess()
        {
            var retriedTimes = 0;

            _currentStatus = LogFlowStatus.Running;
            Log.Info(string.Format("{0}: Started.", _flowStructure.Context.LogType));

            while (true)
            {
                try
                {
                    ExecuteStructure();
                    _tokenSource.Token.ThrowIfCancellationRequested();
                }
                catch (OperationCanceledException)
                {
                    _flowStructure.StopAll();
                    _currentStatus = LogFlowStatus.Stopped;
                    Log.Info(string.Format("{0}: Stopped.", _flowStructure.Context.LogType));
                    break;
                }
                catch (Exception ex)
                {
                    if (retriedTimes < TimesToRetry)
                    {
                        retriedTimes++;
                        _currentStatus = LogFlowStatus.Retrying;

                        Log.Warn(string.Format("{0}: {1}", _flowStructure.Context.LogType, ex));
                        Log.Warn(string.Format("{0}: Retrying {1} times.", _flowStructure.Context.LogType, retriedTimes));
                        Thread.Sleep(TimeSpan.FromSeconds(10));
                        continue;
                    }

                    _flowStructure.StopAll();
                    _currentStatus = LogFlowStatus.Broken;

                    Log.Error(ex);
                    Log.Error(string.Format("{0}: Shut down because broken!", _flowStructure.Context.LogType));
                    break;
                }

                if (_currentStatus == LogFlowStatus.Retrying)
                {
                    _currentStatus = LogFlowStatus.Running;

                    Log.Info(string.Format("{0}: Resuming after {1} times.", _flowStructure.Context.LogType, retriedTimes));
                    retriedTimes = 0;
                }
            }
        }
Exemple #2
0
        private void ExecuteProcess()
        {
            var retriedTimes = 0;

            _currentStatus = LogFlowStatus.Running;
            Log.Info(string.Format("{0}: Started.", _flowStructure.Context.LogType));

            while (true)
            {
                try
                {
                    ExecuteStructure();
                    _tokenSource.Token.ThrowIfCancellationRequested();
                }
                catch (OperationCanceledException)
                {
                    _flowStructure.StopAll();
                    _currentStatus = LogFlowStatus.Stopped;
                    Log.Info(string.Format("{0}: Stopped.", _flowStructure.Context.LogType));
                    break;
                }
                catch (Exception ex)
                {
                    if (retriedTimes < TimesToRetry)
                    {
                        retriedTimes++;
                        _currentStatus = LogFlowStatus.Retrying;

                        Log.Warn(string.Format("{0}: {1}", _flowStructure.Context.LogType, ex));
                        Log.Warn(string.Format("{0}: Retrying {1} times.", _flowStructure.Context.LogType, retriedTimes));
                        Thread.Sleep(TimeSpan.FromSeconds(10));
                        continue;
                    }

                    _flowStructure.StopAll();
                    _currentStatus = LogFlowStatus.Broken;

                    Log.Error(ex);
                    Log.Error(string.Format("{0}: Shut down because broken!", _flowStructure.Context.LogType));
                    break;
                }

                if (_currentStatus == LogFlowStatus.Retrying)
                {
                    _currentStatus = LogFlowStatus.Running;

                    Log.Info(string.Format("{0}: Resuming after {1} times.", _flowStructure.Context.LogType, retriedTimes));
                    retriedTimes = 0;
                }
            }
        }