将依赖事件总线的发布订阅模式,改为直接调用的形式
This commit is contained in:
@@ -47,17 +47,7 @@ namespace Tnb.WarehouseMgr
|
||||
private IEventPublisher _eventPublisher = default!;
|
||||
private ElevatorControlConfiguration _elevatorControlConfiguration = App.Configuration.Build<ElevatorControlConfiguration>();
|
||||
private readonly IServiceProvider _serviceProvider;
|
||||
private static Dictionary<string, Func<CancellationToken?, Task>> _timedFuncMap = new(StringComparer.OrdinalIgnoreCase);
|
||||
static TimedTaskBackgroundService()
|
||||
{
|
||||
//Task.Run(() =>
|
||||
//{
|
||||
// _timedFuncMap = App.EffectiveTypes.AsParallel().Where(t => !t.Namespace.IsNullOrWhiteSpace() && t.Namespace.Equals("Tnb.WarehouseMgr", StringComparison.OrdinalIgnoreCase)).SelectMany(t => t.GetMethods())
|
||||
// .Where(m => m.GetCustomAttribute<TimedAttribute>() != null)
|
||||
// .ToDictionary(x => x.Name, x =>
|
||||
// (Func<CancellationToken?, Task>)Delegate.CreateDelegate(typeof(Func<CancellationToken?, Task>), App.GetService(x.DeclaringType), x));
|
||||
//});
|
||||
}
|
||||
//private static Dictionary<string, Func<CancellationToken?, Task>> _timedFuncMap = new(StringComparer.OrdinalIgnoreCase);
|
||||
public TimedTaskBackgroundService(IServiceProvider serviceProvider)
|
||||
{
|
||||
_serviceProvider = serviceProvider;
|
||||
@@ -66,30 +56,11 @@ namespace Tnb.WarehouseMgr
|
||||
protected override Task ExecuteAsync(CancellationToken stoppingToken)
|
||||
{
|
||||
IsStarted = true;
|
||||
//var queueTask = Task.Run(async () =>
|
||||
// {
|
||||
|
||||
// var channelReader = _serviceProvider.GetRequiredService<ITaskMessageNotify>().Reader;
|
||||
|
||||
// CancellationTokenSource? cts = new();
|
||||
|
||||
// while (channelReader != null && await channelReader.WaitToReadAsync())
|
||||
// {
|
||||
// while (channelReader.TryRead(out var message))
|
||||
// {
|
||||
// if (_timedFuncMap.ContainsKey(message.TaskName))
|
||||
// {
|
||||
// await _timedFuncMap[message.TaskName].Invoke(stoppingToken);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }, stoppingToken);
|
||||
|
||||
var timedTask = Task.Run(() =>
|
||||
{
|
||||
_eventPublisher = App.GetRequiredService<IEventPublisher>();
|
||||
var whSvc = App.GetRequiredService<IWareHouseService>();
|
||||
TimedTask(token => whSvc.GenTaskExecute(), stoppingToken, 1);
|
||||
|
||||
//电梯Agv心跳检测
|
||||
TimedTask(async token =>
|
||||
{
|
||||
@@ -130,6 +101,7 @@ namespace Tnb.WarehouseMgr
|
||||
{
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user