新增 ,定时器自定义异常类
This commit is contained in:
@@ -3,17 +3,24 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Aop.Api.Domain;
|
||||
using JNPF;
|
||||
using JNPF.Common.Core.Manager;
|
||||
using JNPF.Common.Dtos.Message;
|
||||
using JNPF.Common.Extension;
|
||||
using JNPF.Common.Security;
|
||||
using JNPF.EventBus;
|
||||
using JNPF.EventHandler;
|
||||
using JNPF.FriendlyException;
|
||||
using JNPF.Logging;
|
||||
using JNPF.Message.Interfaces.Message;
|
||||
using JNPF.Systems.Entitys.System;
|
||||
using Microsoft.CodeAnalysis.CSharp.Syntax;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
using Microsoft.Extensions.Options;
|
||||
using Tnb.Common.Extension;
|
||||
using Tnb.WarehouseMgr.Entities.Dto.Inputs;
|
||||
using Tnb.WarehouseMgr.Entities.Exceptions;
|
||||
using Tnb.WarehouseMgr.Interfaces;
|
||||
|
||||
namespace Tnb.WarehouseMgr
|
||||
@@ -24,11 +31,11 @@ namespace Tnb.WarehouseMgr
|
||||
/// </summary>
|
||||
public class TimedTaskBackgroundService : BackgroundService
|
||||
{
|
||||
private ISendMessageService? _sendService;
|
||||
private IEventPublisher _eventPublisher;
|
||||
|
||||
protected override Task ExecuteAsync(CancellationToken stoppingToken) => Task.Run(() =>
|
||||
{
|
||||
//_sendService = App.GetRequiredService<ISendMessageService>();
|
||||
//_eventPublisher = App.GetRequiredService<IEventPublisher>();
|
||||
List<string> toUserIds = new List<string>() { "25398501929509" };
|
||||
//生成任务执行
|
||||
CancellationTokenSource genTaskCTS = new();
|
||||
@@ -55,9 +62,22 @@ namespace Tnb.WarehouseMgr
|
||||
{
|
||||
while (!token.IsCancellationRequested)
|
||||
{
|
||||
await action(cts).Catch(ex =>
|
||||
await action(cts).Catch(async ex =>
|
||||
{
|
||||
//notify operator
|
||||
if (ex is TimedTaskException timedTaskEx)
|
||||
{
|
||||
await _eventPublisher.PublishAsync(new LogEventSource("Log:CreateExLog", options, new SysLogEntity
|
||||
{
|
||||
Id = SnowflakeIdHelper.NextId(),
|
||||
Category = 4,
|
||||
IPAddress = NetHelper.Ip,
|
||||
RequestURL = httpRequest.Path,
|
||||
RequestMethod = httpRequest.Method,
|
||||
Json = timedTaskEx + "\n" + context.Exception.StackTrace + "\n" + context.Exception.TargetSite.GetParameters().ToString(),
|
||||
PlatForm = string.Format("{0}-{1}", userAgent.OS.ToString(), userAgent.RawValue),
|
||||
CreatorTime = DateTime.Now
|
||||
}));
|
||||
}
|
||||
});
|
||||
await Task.Delay(1000);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user