HealthCheckTriggerJob.cs 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. using EVCB_OCPP.Domain;
  2. using EVCB_OCPP.WSServer.Service.WsService;
  3. using Microsoft.Extensions.Logging;
  4. using OCPPServer.Protocol;
  5. using Quartz;
  6. using System;
  7. using System.Collections.Generic;
  8. using System.Linq;
  9. using System.Text;
  10. using System.Threading.Tasks;
  11. namespace EVCB_OCPP.WSServer.Jobs;
  12. [DisallowConcurrentExecution]
  13. public class HealthCheckTriggerJob : IJob
  14. {
  15. public HealthCheckTriggerJob(
  16. ProtalServer protalServer,
  17. ILogger<HealthCheckTriggerJob> logger)
  18. {
  19. this.protalServer = protalServer;
  20. this.logger = logger;
  21. }
  22. private readonly ProtalServer protalServer;
  23. private readonly ILogger<HealthCheckTriggerJob> logger;
  24. public Task Execute(IJobExecutionContext context)
  25. {
  26. //logger.LogDebug("{0} Started", nameof(HealthCheckTriggerJob));
  27. Dictionary<string, WsClientData> _copyClientDic = protalServer.GetClientDic();
  28. var removeClients = _copyClientDic.Where(x => x.Value.LastActiveTime < DateTime.UtcNow.AddSeconds(-300)).Select(x => x.Value).ToList();
  29. foreach (var session in removeClients)
  30. {
  31. logger.LogDebug("Server forced to shut down ChargeBox ({0}: LastActiveTime{1})", session.ChargeBoxId, session.LastActiveTime);
  32. protalServer.RemoveClient(session);
  33. }
  34. return Task.CompletedTask;
  35. }
  36. }