Phase0_Day2_volpro_side
This commit is contained in:
26
api_sqlsugar/Warehouse/Services/HeartbeatMonitorJob.cs
Normal file
26
api_sqlsugar/Warehouse/Services/HeartbeatMonitorJob.cs
Normal file
@@ -0,0 +1,26 @@
|
||||
using Quartz;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
|
||||
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 = "离线";
|
||||
await gwSvc.UpdateAsync(node);
|
||||
await devSvc.UpdateAsync(x => x.GatewayNodeId == node.NodeId,
|
||||
x => new base_device { IsOnline = "离线" });
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user