28 lines
913 B
C#
28 lines
913 B
C#
using Quartz;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
using Warehouse.IServices;
|
|
|
|
namespace VolPro.Warehouse.Services;
|
|
|
|
public class HeartbeatMonitorJob : IJob
|
|
{
|
|
public async Task Execute(IJobExecutionContext context)
|
|
{
|
|
var sp = (IServiceProvider)context.JobDetail.JobDataMap["ServiceProvider"];
|
|
var gwSvc = sp.GetService<Igateway_nodesService>();
|
|
var devSvc = sp.GetService<Ibase_deviceService>();
|
|
|
|
var timeout = DateTime.Now.AddSeconds(-30);
|
|
var offlineNodes = await gwSvc.FindAsIQueryable(x => x.IsOnline == "在线" && x.LastHeartbeat < timeout)
|
|
.ToListAsync();
|
|
|
|
foreach (var node in offlineNodes)
|
|
{
|
|
node.IsOnline = "离线";
|
|
gwSvc.Update(node);
|
|
await devSvc.UpdateAsync(x => x.GatewayNodeId == node.NodeId,
|
|
x => new base_device { IsOnline = "离线" });
|
|
}
|
|
}
|
|
}
|