using System;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Extensions.Hosting;
using MySystem;

public class TimerStatTimer : BackgroundService
{
    protected override async Task ExecuteAsync(CancellationToken stoppingToken)
    {
        while (!stoppingToken.IsCancellationRequested)
        {
            int timespan = 10000;
            await Task.Delay(timespan).ContinueWith(tsk =>
            {
                DoWorks();
            });
        }
    }

    private void DoWorks()
    {
        string MsgContent = RedisDbconn.Instance.RPop<string>("TimerStat");
        if (!string.IsNullOrEmpty(MsgContent))
        {
            JobMqMsg job = Newtonsoft.Json.JsonConvert.DeserializeObject<JobMqMsg>(MsgContent);
            StatTimerService.Instance.Start(job);
        }
    }
}