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

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

    private void Start()
    {
        string data = RedisDbconn.Instance.RPop<string>("MainPopWaitList");
        if (!string.IsNullOrEmpty(data))
        {
            JobMqMsg job = Newtonsoft.Json.JsonConvert.DeserializeObject<JobMqMsg>(data);
            ReceiveTaskService.Instance.Start(job);
        }
        else
        {
            Thread.Sleep(2000);
        }
    }
}