using System;
using System.Threading;
using System.Threading.Tasks;
using Hangfire;
using JiShe.CollectBus.Common.Attributes;
using Microsoft.Extensions.Logging;
using Volo.Abp.BackgroundWorkers.Hangfire;
using Volo.Abp.DependencyInjection;
using Volo.Abp.Uow;

namespace JiShe.CollectBus.Workers
{
    public class EpiCollectWorker : HangfireBackgroundWorkerBase, ITransientDependency,ICollectWorker
    {
        private readonly ILogger<EpiCollectWorker> _logger;

        /// <summary>
        /// Initializes a new instance of the <see cref="EpiCollectWorker"/> class.
        /// </summary>
        /// <param name="logger">The logger.</param>
        public EpiCollectWorker(ILogger<EpiCollectWorker> logger)
        {
            _logger = logger;
            RecurringJobId = nameof(EpiCollectWorker);
            CronExpression = Cron.Daily();
            
        }


        public override Task DoWorkAsync(CancellationToken cancellationToken = new CancellationToken())
        {
            using (var uow = LazyServiceProvider.LazyGetRequiredService<IUnitOfWorkManager>().Begin())
            {
                Logger.LogInformation("Executed MyLogWorker..!");
                return Task.CompletedTask;
            }
        }
    }
}
