This commit is contained in:
alex
2023-08-15 15:19:14 +08:00
parent a6a4a1ebc2
commit 26dd70efb3
2 changed files with 7 additions and 10 deletions

View File

@@ -44,9 +44,10 @@ namespace Tnb.WarehouseMgr
static TimedTaskBackgroundService()
{
_timedFuncMap = App.EffectiveTypes.AsParallel().Where(t => !t.Namespace.IsNullOrWhiteSpace() && t.Namespace.Contains("Tnb.WarehouseMgr")).SelectMany(t => t.GetMethods())
.Where(m => m.GetCustomAttribute<TimedAttribute>() != null)
.ToDictionary(x => x.Name, x =>
(Func<CancellationTokenSource?, Task>)Delegate.CreateDelegate(typeof(Func<CancellationTokenSource?, Task>), App.GetService(x.DeclaringType), x));
.Where(m => m.GetCustomAttribute<TimedAttribute>() != null)
.ToDictionary(x => x.Name, x =>
(Func<CancellationTokenSource?, Task>)Delegate.CreateDelegate(typeof(Func<CancellationTokenSource?, Task>), App.GetService(x.DeclaringType), x));
}
public TimedTaskBackgroundService(IServiceProvider serviceProvider)
{
@@ -59,7 +60,7 @@ namespace Tnb.WarehouseMgr
var channelReader = _serviceProvider.GetRequiredService<ITaskMessageNotify>().Reader;
CancellationTokenSource? cts = new();
while (channelReader != null && await channelReader.WaitToReadAsync())
{
while (channelReader.TryRead(out var message))

View File

@@ -42,7 +42,6 @@ namespace Tnb.WarehouseMgr
private readonly IWareHouseService _wareHouseService;
private readonly IBillRullService _billRullService;
private readonly IUserManager _userManager;
private readonly ChannelWriter<NotifyMessage> _channelWriter;
public WmsPDAInbaleService(
ISqlSugarRepository<WmsCarryH> repository,
@@ -51,7 +50,7 @@ namespace Tnb.WarehouseMgr
IWareHouseService wareHouseService,
IUserManager userManager,
IBillRullService billRullService,
ChannelWriter<NotifyMessage> channelWriter)
ITaskMessageNotify taskMessageNotify):base(taskMessageNotify.Writer)
{
_db = repository.AsSugarClient();
_runService = runService;
@@ -59,7 +58,6 @@ namespace Tnb.WarehouseMgr
_wareHouseService = wareHouseService;
_userManager = userManager;
_billRullService = billRullService;
_channelWriter = channelWriter;
OverideFuncs.CreateAsync = Inbale;
}
@@ -173,9 +171,7 @@ namespace Tnb.WarehouseMgr
}
finally
{
//向队列写入消息
NotifyMessage message = new() { TaskName = nameof(IWareHouseService.GenTaskExecute) };
await _channelWriter.WriteAsync(message);
await Publish(nameof(IWareHouseService.GenTaskExecute));
}
return Task.FromResult(true);
}