private static void RunProcess(IServerProcess process, BackgroundProcessContext context)
        {
            // Long-running tasks are based on custom threads (not threadpool ones) as in 
            // .NET Framework 4.5, so we can try to set custom thread name to simplify the
            // debugging experience.
            TrySetThreadName(process.ToString());

            // LogProvider.GetLogger does not throw any exception, that is why we are not
            // using the `try` statement here. It does not return `null` value as well.
            var logger = LogProvider.GetLogger(process.GetProcessType());
            logger.Debug($"Background process '{process}' started.");

            try
            {
                process.Execute(context);
            }
            catch (Exception ex)
            {
                if (ex is OperationCanceledException && context.IsShutdownRequested)
                {
                    // Graceful shutdown
                    logger.Trace($"Background process '{process}' was stopped due to a shutdown request.");
                }
                else
                {
                    logger.FatalException(
                        $"Fatal error occurred during execution of '{process}' process. It will be stopped. See the exception for details.",
                        ex);
                }
            }

            logger.Debug($"Background process '{process}' stopped.");
        }
Example #2
0
        private static void RunProcess(IServerProcess process, BackgroundProcessContext context)
        {
            // Long-running tasks are based on custom threads (not threadpool ones) as in
            // .NET Framework 4.5, so we can try to set custom thread name to simplify the
            // debugging experience.
            TrySetThreadName(process.ToString());

            // LogProvider.GetLogger does not throw any exception, that is why we are not
            // using the `try` statement here. It does not return `null` value as well.
            var logger = LogProvider.GetLogger(process.GetProcessType());

            logger.DebugFormat("Background process '{0}' started.", process);

            try
            {
                process.Execute(context);
            }
            catch (OperationCanceledException)
            {
            }
            catch (Exception ex)
            {
                logger.FatalException(
                    String.Format(
                        "Fatal error occurred during execution of '{0}' process. It will be stopped. See the exception for details.",
                        process),
                    ex);
            }

            logger.DebugFormat("Background process '{0}' stopped.", process);
        }
        public AutomaticRetryProcess([NotNull] IServerProcess innerProcess)
        {
            if (innerProcess == null) throw new ArgumentNullException("innerProcess");

            _innerProcess = innerProcess;
            _logger = LogProvider.GetLogger(_innerProcess.GetProcessType());

            MaxRetryAttempts = DefaultMaxRetryAttempts;
            MaxAttemptDelay = DefaultMaxAttemptDelay;
            DelayCallback = GetBackOffMultiplier;
        }
        public AutomaticRetryProcess([NotNull] IServerProcess innerProcess)
        {
            if (innerProcess == null)
            {
                throw new ArgumentNullException(nameof(innerProcess));
            }

            _innerProcess = innerProcess;
            _logger       = LogProvider.GetLogger(_innerProcess.GetProcessType());

            MaxRetryAttempts = DefaultMaxRetryAttempts;
            MaxAttemptDelay  = DefaultMaxAttemptDelay;
            DelayCallback    = GetBackOffMultiplier;
        }
Example #5
0
        /// <summary>
        /// 在当前进程中运行
        /// </summary>
        /// <param name="process"></param>
        /// <param name="context"></param>
        private static void RunProcess(IServerProcess process, BackgroundProcessContext context)
        {
            // Long-running tasks are based on custom threads (not threadpool ones) as in .NET Framework 4.5, so we can try to set custom thread name to simplify the debugging experience.
            // 与. net Framework 4.5中一样,长时间运行的任务基于自定义线程(而不是线程池线程),因此我们可以尝试设置自定义线程名,以简化调试体验。
            TrySetThreadName(process.ToString());

            // LogProvider.GetLogger does not throw any exception, that is why we are not using the `try` statement here.
            // GetLogger不会抛出任何异常,这就是我们在这里不使用‘try’语句的原因。
            // It does not return `null` value as well.
            // 它也不返回' null '值。
            var logger = LogProvider.GetLogger(process.GetProcessType());

            //logger.Debug($"Background process '{process}' started.");
            logger.Debug($"后台进程 '{process}' 启动了。");

            try
            {
                process.Execute(context);
            }
            catch (Exception ex)
            {
                if (ex is OperationCanceledException && context.IsShutdownRequested)
                {
                    // Graceful shutdown
                    //logger.Trace($"Background process '{process}' was stopped due to a shutdown request.");
                    logger.Trace($"后台进程 '{process}' 由于关闭请求而停止。");
                }
                else
                {
                    logger.FatalException(
                        $"Fatal error occurred during execution of '{process}' process. It will be stopped. See the exception for details.",
                        ex);
                }
            }

            //logger.Debug($"Background process '{process}' stopped.");
            logger.Debug($"后台进程 '{process}' 停止了。");
        }