Skip to content
  • P
    Projects
  • G
    Groups
  • S
    Snippets
  • Help

丁松杰 / Pole

  • This project
    • Loading...
  • Sign in
Go to a project
  • Project
  • Repository
  • Issues 0
  • Merge Requests 0
  • Pipelines
  • Wiki
  • Snippets
  • Members
  • Activity
  • Graph
  • Charts
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
  • Files
  • Commits
  • Branches
  • Tags
  • Contributors
  • Graph
  • Compare
  • Charts
Switch branch/tag
  • Pole
  • src
  • Pole.ReliableMessage
  • Processor
  • LoopProcessor.cs
Find file
BlameHistoryPermalink
  • 丁松杰's avatar
    添加 可靠消息 组件 · eb350c31
    丁松杰 committed 5 years ago
    eb350c31
LoopProcessor.cs 1.71 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
using Pole.ReliableMessage.Abstraction;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;

namespace Pole.ReliableMessage.Processor
{
    public class LoopProcessor : ProcessorBase
    {
        private IProcessor _processor;
        private readonly ILoggerFactory _loggerFactory;
        private readonly ITimeHelper _timeHelper;

        public LoopProcessor(IProcessor processor, ILoggerFactory loggerFactory, ITimeHelper timeHelper)
        {
            _processor = processor;
            _loggerFactory = loggerFactory;
            _timeHelper = timeHelper;
        }
        public override string Name => "LoopProcessor";
        public override async Task Process(ProcessingContext context)
        {
            var logger = _loggerFactory.CreateLogger<LoopProcessor>();

            while (!context.IsStopping)
            {
                try
                {
                    logger.LogDebug($"{_timeHelper.GetAppropriateFormatedDateString()}...{ this.ToString() } process start");

                    await _processor.Process(context);

                    logger.LogDebug($"{_timeHelper.GetAppropriateFormatedDateString()}...{ this.ToString() } process compelete");
                }
                catch (Exception ex)
                {
                    logger.LogError(ex, $"{_timeHelper.GetAppropriateFormatedDateString()}...{ this.ToString() } process error");
                }
            }
        }
        public override string ToString()
        {
            var strArray = new string[2];
            strArray[0] = Name;
            strArray[1] = _processor.Name;
            return string.Join("_", strArray);
        }
    }
}