28 lines
827 B
C#
28 lines
827 B
C#
using Quartz;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
using Warehouse.IRepositories;
|
|
using VolPro.Entity.DomainModels;
|
|
|
|
namespace VolPro.Warehouse.Services;
|
|
|
|
public class HeartbeatMonitorJob : IJob
|
|
{
|
|
public async Task Execute(IJobExecutionContext context)
|
|
{
|
|
var sp = (IServiceProvider)context.JobDetail.JobDataMap["ServiceProvider"];
|
|
var gwRepo = sp.GetService<Igateway_nodesRepository>();
|
|
var db = gwRepo.DbContext;
|
|
var timeout = DateTime.Now.AddSeconds(-30);
|
|
|
|
var offlineNodes = db.Queryable<gateway_nodes>()
|
|
.Where(x => x.IsOnline == "在线" && x.LastHeartbeat < timeout)
|
|
.ToList();
|
|
|
|
foreach (var node in offlineNodes)
|
|
{
|
|
node.IsOnline = "离线";
|
|
db.Updateable(node).ExecuteCommand();
|
|
}
|
|
}
|
|
}
|