remove 移除服务端发起心跳
This commit is contained in:
@@ -1,43 +1,43 @@
|
||||
using System.Net;
|
||||
using System.Net.Sockets;
|
||||
using Dlhis.Entity.Basic.Entity;
|
||||
using Dlhis.Entity.Device.Entities;
|
||||
using Dlhis.ScheduledTask.Attributes;
|
||||
using Kurisu.AspNetCore.CustomClass;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace Dlhis.ScheduledTask.Jobs;
|
||||
|
||||
/// <summary>
|
||||
/// 设备心跳
|
||||
/// </summary>
|
||||
[RecurringJob(nameof(HeartbeatJob), "0/30 * * * * ?", Name = "设备心跳")]
|
||||
public class HeartbeatJob : BaseJob
|
||||
{
|
||||
public HeartbeatJob(IServiceProvider serviceProvider) : base(serviceProvider)
|
||||
{
|
||||
}
|
||||
|
||||
protected override async Task RunAsync(IServiceProvider serviceProvider)
|
||||
{
|
||||
var devices = await DbContext.Queryable<DeviceEntity>().Where(x => x.Enable).Where(x => x.HeartbeatInterval > 0).ToListAsync();
|
||||
|
||||
await Parallel.ForEachAsync(devices, async (device, cancellationToken) =>
|
||||
{
|
||||
try
|
||||
{
|
||||
var ipInfo = JsonConvert.DeserializeObject<IPPortDto>(device.ConnectionInfo);
|
||||
await new TcpClient().ConnectAsync(IPAddress.Parse(ipInfo.IP), ipInfo.Port, cancellationToken);
|
||||
|
||||
await DbContext.Updateable<DeviceRegistryEntity>()
|
||||
.SetColumns(x => x.LastHeartbeatTime == DateTime.Now)
|
||||
.Where(x => x.DeviceUniqueNo == device.UniqueNo)
|
||||
.ExecuteCommandAsync(cancellationToken);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
//ignore
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
// using System.Net;
|
||||
// using System.Net.Sockets;
|
||||
// using Dlhis.Entity.Basic.Entity;
|
||||
// using Dlhis.Entity.Device.Entities;
|
||||
// using Dlhis.ScheduledTask.Attributes;
|
||||
// using Kurisu.AspNetCore.CustomClass;
|
||||
// using Newtonsoft.Json;
|
||||
//
|
||||
// namespace Dlhis.ScheduledTask.Jobs;
|
||||
//
|
||||
// /// <summary>
|
||||
// /// 设备心跳
|
||||
// /// </summary>
|
||||
// [RecurringJob(nameof(HeartbeatJob), "0/30 * * * * ?", Name = "设备心跳")]
|
||||
// public class HeartbeatJob : BaseJob
|
||||
// {
|
||||
// public HeartbeatJob(IServiceProvider serviceProvider) : base(serviceProvider)
|
||||
// {
|
||||
// }
|
||||
//
|
||||
// protected override async Task RunAsync(IServiceProvider serviceProvider)
|
||||
// {
|
||||
// var devices = await DbContext.Queryable<DeviceEntity>().Where(x => x.Enable).Where(x => x.HeartbeatInterval > 0).ToListAsync();
|
||||
//
|
||||
// await Parallel.ForEachAsync(devices, async (device, cancellationToken) =>
|
||||
// {
|
||||
// try
|
||||
// {
|
||||
// var ipInfo = JsonConvert.DeserializeObject<IPPortDto>(device.ConnectionInfo);
|
||||
// await new TcpClient().ConnectAsync(IPAddress.Parse(ipInfo.IP), ipInfo.Port, cancellationToken);
|
||||
//
|
||||
// await DbContext.Updateable<DeviceRegistryEntity>()
|
||||
// .SetColumns(x => x.LastHeartbeatTime == DateTime.Now)
|
||||
// .Where(x => x.DeviceUniqueNo == device.UniqueNo)
|
||||
// .ExecuteCommandAsync(cancellationToken);
|
||||
// }
|
||||
// catch (Exception)
|
||||
// {
|
||||
// //ignore
|
||||
// }
|
||||
// });
|
||||
// }
|
||||
// }
|
||||
Reference in New Issue
Block a user