定时任务代码调整

This commit is contained in:
alex
2023-08-15 16:54:40 +08:00
parent b7500efd7f
commit 9d780a5694

View File

@@ -57,7 +57,9 @@ namespace Tnb.WarehouseMgr
_serviceProvider = serviceProvider;
}
protected override Task ExecuteAsync(CancellationToken stoppingToken) => Task.Run(async () =>
protected override Task ExecuteAsync(CancellationToken stoppingToken)
{
var queueTask = Task.Run(async () =>
{
var channelReader = _serviceProvider.GetRequiredService<ITaskMessageNotify>().Reader;
@@ -75,15 +77,17 @@ namespace Tnb.WarehouseMgr
}
}
#region
//_eventPublisher = App.GetRequiredService<IEventPublisher>();
//List<string> toUserIds = new List<string>() { "25398501929509" };
}, stoppingToken);
var timedTask = Task.Run(() =>
{
_eventPublisher = App.GetRequiredService<IEventPublisher>();
////生成任务执行
//CancellationTokenSource genTaskCTS = new();
//CancellationTokenSource kittingOutAddCts = new();
//CancellationTokenSource kittingOutShippedCts = new();
//CancellationTokenSource setSortingCts = new();
CancellationTokenSource kittingOutAddCts = new();
CancellationTokenSource kittingOutShippedCts = new();
CancellationTokenSource setSortingCts = new();
CancellationTokenSource isMinStorageCts = new();
//var wareHouseService = App.GetRequiredService<IWareHouseService>();
//TimedTask(cts => wareHouseService.GenTaskExecute(cts), genTaskCTS);
//齐套出库
@@ -93,8 +97,16 @@ namespace Tnb.WarehouseMgr
//齐套分拣
var setSortingService = App.GetRequiredService<IWmsSetSortingService>();
TimedTask(cts => setSortingService.PackSortingByAdd(cts), setSortingCts, 1);
#endregion
}, stoppingToken);
var transferSignService = App.GetRequiredService<IWmsPDATransferSignService>();
TimedTask(cts => transferSignService.IsMinStorage(cts), isMinStorageCts, 30, TimeSpanUnit.Minutes);
});
return Task.WhenAll(queueTask, timedTask);
}
private Task TimedTask(Func<CancellationTokenSource, Task> action, CancellationTokenSource cts, int interval, TimeSpanUnit timeType = TimeSpanUnit.Seconds)
{
@@ -136,6 +148,7 @@ namespace Tnb.WarehouseMgr
TimeSpanUnit.Minutes => Task.Delay(TimeSpan.FromMinutes(interval)),
TimeSpanUnit.Hours => Task.Delay(TimeSpan.FromHours(interval)),
TimeSpanUnit.Days => Task.Delay(TimeSpan.FromDays(interval)),
_ => throw new NotImplementedException()
};
return delayTask;
}