using EVCB_OCPP.WSServer.Service;
using Microsoft.Extensions.Logging;
using Quartz;
using RestSharp;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace EVCB_OCPP.WSServer.Jobs
{
    [DisallowConcurrentExecution]
    public class GoogleCheckJob : IJob
    {
        public GoogleCheckJob(ILogger<GoogleCheckJob> logger)
        {
            this.logger = logger;
        }

        private readonly ILogger<GoogleCheckJob> logger;

        public async Task Execute(IJobExecutionContext context)
        {
            var client = new RestClient("http://www.google.com");
            var stopWatch = Stopwatch.StartNew();
            await client.ExecuteAsync(new RestRequest("", method: Method.Get));
            stopWatch.Stop();

            if (stopWatch.ElapsedMilliseconds > 1000)
            {
                logger.LogInformation($"Google Get Cost {stopWatch.ElapsedMilliseconds}ms");
            }
        }
    }
}
