电梯Agv心跳代码调整
This commit is contained in:
@@ -10,6 +10,7 @@ using NPOI.OpenXmlFormats.Dml.Diagram;
|
||||
using Tnb.Common.Extension;
|
||||
using Tnb.Common.Utils;
|
||||
using Tnb.WarehouseMgr.Entities.Configs;
|
||||
using Tnb.WarehouseMgr.Entities.Consts;
|
||||
using Tnb.WarehouseMgr.Entities.Enums;
|
||||
using Tnb.WarehouseMgr.Entities.Exceptions;
|
||||
|
||||
@@ -42,43 +43,21 @@ namespace Tnb.WarehouseMgr
|
||||
//电梯Agv心跳检测
|
||||
_ = TimedTask(async token =>
|
||||
{
|
||||
Dictionary<string, string> parameter = new()
|
||||
foreach (var devName in _elevatorControlConfiguration.HeartbeatDevNames)
|
||||
{
|
||||
["DevName"] = _elevatorControlConfiguration.DevName3,
|
||||
["TagName"] = "AGVKeepalive",
|
||||
["Value"] = "123",
|
||||
["token"] = _elevatorControlConfiguration.token
|
||||
};
|
||||
string result = await HttpClientHelper.GetAsync(_elevatorControlConfiguration.WriteTagUrl, pars: parameter);
|
||||
await Console.Out.WriteLineAsync($"{_elevatorControlConfiguration.DevName3.Match(@"\d+")}#梯, 心跳检测结果:{result}");
|
||||
}, stoppingToken, 30, TimeSpanUnit.Seconds);
|
||||
_ = TimedTask(async token =>
|
||||
{
|
||||
Dictionary<string, string> parameter = new()
|
||||
{
|
||||
["DevName"] = _elevatorControlConfiguration.DevName4,
|
||||
["TagName"] = "AGVKeepalive",
|
||||
["Value"] = "123",
|
||||
["token"] = _elevatorControlConfiguration.token
|
||||
};
|
||||
string result = await HttpClientHelper.GetAsync(_elevatorControlConfiguration.WriteTagUrl, pars: parameter);
|
||||
await Console.Out.WriteLineAsync($"{_elevatorControlConfiguration.DevName4.Match(@"\d+")}#梯,心跳检测结果:{result}");
|
||||
}, stoppingToken, 30, TimeSpanUnit.Seconds);
|
||||
////齐套出库
|
||||
/*var kittingOutService = App.GetRequiredService<IWmskittingOutService>();
|
||||
TimedTask(token => kittingOutService.KittingOutByAdd(token), stoppingToken, 1);
|
||||
TimedTask(token => kittingOutService.KittingOutByIsToBeShipped(token), stoppingToken, 1);
|
||||
//齐套分拣
|
||||
var setSortingService = App.GetRequiredService<IWmsSetSortingService>();
|
||||
TimedTask(token => setSortingService.PackSortingByAdd(token), stoppingToken, 2);
|
||||
|
||||
Dictionary<string, string> parameter = new()
|
||||
{
|
||||
["DevName"] = devName,
|
||||
["TagName"] = ElevatorConsts.AGVKeepalive,
|
||||
["Value"] = "123",
|
||||
["token"] = _elevatorControlConfiguration.token
|
||||
};
|
||||
string result = await HttpClientHelper.GetAsync(_elevatorControlConfiguration.WriteTagUrl, pars: parameter);
|
||||
await Console.Out.WriteLineAsync($"{devName.Match(@"\d+")}#梯, 心跳检测结果:{result}");
|
||||
}
|
||||
}, stoppingToken, 30);
|
||||
|
||||
//最低库存检查
|
||||
var transferSignService = App.GetRequiredService<IWmsPDATransferSignService>();
|
||||
TimedTask(token => transferSignService.IsMinStorage(token), stoppingToken, 30, TimeSpanUnit.Minutes);*/
|
||||
|
||||
}, stoppingToken);
|
||||
|
||||
});
|
||||
return timedTask;
|
||||
}
|
||||
|
||||
@@ -86,14 +65,42 @@ namespace Tnb.WarehouseMgr
|
||||
|
||||
private Task TimedTask(Func<CancellationToken, Task> action, CancellationToken ct, int interval, TimeSpanUnit timeType = TimeSpanUnit.Seconds)
|
||||
{
|
||||
CancellationToken token = ct;
|
||||
return Task.Factory.StartNew(async () =>
|
||||
// CancellationToken token = ct;
|
||||
// return Task.Factory.StartNew(async () =>
|
||||
// {
|
||||
// while (!token.IsCancellationRequested)
|
||||
// {
|
||||
// await action(ct).Catch(async ex =>
|
||||
// {
|
||||
|
||||
// if (ex is TimedTaskException timedTaskEx and not null)
|
||||
// {
|
||||
// await _eventPublisher.PublishAsync(new LogEventSource("Log:CreateExLog", timedTaskEx.options!, new SysLogEntity
|
||||
// {
|
||||
// Id = SnowflakeIdHelper.NextId(),
|
||||
// Category = 4,
|
||||
// UserId = timedTaskEx.UserId,
|
||||
// UserName = timedTaskEx.UserName,
|
||||
// IPAddress = NetHelper.Ip,
|
||||
// RequestURL = timedTaskEx.RequestURL,
|
||||
// RequestMethod = timedTaskEx.RequestMethod,
|
||||
// Json = timedTaskEx + "\n" + timedTaskEx.InnerException?.StackTrace + "\n" + timedTaskEx?.TargetSite?.GetParameters().ToString(),
|
||||
// //PlatForm = string.Format("{0}-{1}", userAgent.OS.ToString(), userAgent.RawValue),
|
||||
// CreatorTime = DateTime.Now
|
||||
// }));
|
||||
// }
|
||||
// });
|
||||
// await TaskDelay(timeType, interval);
|
||||
// }
|
||||
// }, ct, TaskCreationOptions.None, new CustomerTaskScheduler());
|
||||
|
||||
return Task.Run(async () =>
|
||||
{
|
||||
while (!token.IsCancellationRequested)
|
||||
while (!ct.IsCancellationRequested)
|
||||
{
|
||||
|
||||
await action(ct).Catch(async ex =>
|
||||
{
|
||||
|
||||
if (ex is TimedTaskException timedTaskEx and not null)
|
||||
{
|
||||
await _eventPublisher.PublishAsync(new LogEventSource("Log:CreateExLog", timedTaskEx.options!, new SysLogEntity
|
||||
@@ -113,37 +120,7 @@ namespace Tnb.WarehouseMgr
|
||||
});
|
||||
await TaskDelay(timeType, interval);
|
||||
}
|
||||
}, ct, TaskCreationOptions.None, new CustomerTaskScheduler());
|
||||
|
||||
#region ThreadPool 线程运行会导致线程饥饿
|
||||
//return Task.Run(async () =>
|
||||
//{
|
||||
// while (!token.IsCancellationRequested)
|
||||
// {
|
||||
|
||||
// await action(cts).Catch(async ex =>
|
||||
// {
|
||||
// if (ex is TimedTaskException timedTaskEx and not null)
|
||||
// {
|
||||
// await _eventPublisher.PublishAsync(new LogEventSource("Log:CreateExLog", timedTaskEx.options!, new SysLogEntity
|
||||
// {
|
||||
// Id = SnowflakeIdHelper.NextId(),
|
||||
// Category = 4,
|
||||
// UserId = timedTaskEx.UserId,
|
||||
// UserName = timedTaskEx.UserName,
|
||||
// IPAddress = NetHelper.Ip,
|
||||
// RequestURL = timedTaskEx.RequestURL,
|
||||
// RequestMethod = timedTaskEx.RequestMethod,
|
||||
// Json = timedTaskEx + "\n" + timedTaskEx.InnerException?.StackTrace + "\n" + timedTaskEx?.TargetSite?.GetParameters().ToString(),
|
||||
// //PlatForm = string.Format("{0}-{1}", userAgent.OS.ToString(), userAgent.RawValue),
|
||||
// CreatorTime = DateTime.Now
|
||||
// }));
|
||||
// }
|
||||
// });
|
||||
// await TaskDelay(timeType, interval);
|
||||
// }
|
||||
//}, token);
|
||||
#endregion
|
||||
}, ct);
|
||||
}
|
||||
|
||||
public override Task StopAsync(CancellationToken cancellationToken)
|
||||
|
||||
Reference in New Issue
Block a user