using PARR.TemplateTaskGenerator;

namespace PARR.TemplateTaskGeneratorWorker
{
    public class Worker : BackgroundService
    {
        private readonly ILogger<Worker> _logger;
        private readonly IMqTemplateTaskGenerator mqTemplateTaskGenerator;

        public Worker(
            ILogger<Worker> logger,
            IMqTemplateTaskGenerator mqTemplateTaskGenerator
            )
        {
            _logger = logger;
            this.mqTemplateTaskGenerator = mqTemplateTaskGenerator;
        }

        protected override async Task ExecuteAsync(CancellationToken stoppingToken)
        {
            await mqTemplateTaskGenerator.StartAsync();
        }


        public override Task StopAsync(CancellationToken cancellationToken)
        {
            mqTemplateTaskGenerator.StopAsync().Wait();

            return base.StopAsync(cancellationToken);
        }
    }
}
