HealthCheckTriggerJob.cs 1.3 KB

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