using FastGithub.Scanner;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Options;
using System.Threading;
using System.Threading.Tasks;
namespace FastGithub
{
    /// 
    /// 完整扫描后台服务
    /// 
    sealed class GithubFullScanHostedService : BackgroundService
    {
        private readonly GithubScanService githubScanService;
        private readonly IOptionsMonitor options;
        /// 
        /// 完整扫描后台服务
        /// 
        /// 
        /// 
        public GithubFullScanHostedService(
            GithubScanService githubScanService,
            IOptionsMonitor options)
        {
            this.githubScanService = githubScanService;
            this.options = options;
        }
        /// 
        /// 后台轮询扫描
        /// 
        /// 
        /// 
        protected override async Task ExecuteAsync(CancellationToken stoppingToken)
        {
            await githubScanService.ScanFastAsync(stoppingToken);
            while (stoppingToken.IsCancellationRequested == false)
            {
                await githubScanService.ScanAllAsync(stoppingToken);
                await Task.Delay(this.options.CurrentValue.FullScanInterval, stoppingToken);
            }
        }
    }
}