定时任务,出现异常是将数据推送到系统异常日志以供查看

This commit is contained in:
alex
2023-08-10 10:20:14 +08:00
parent 1bbb30f135
commit 47ab94b3ef
3 changed files with 60 additions and 24 deletions

View File

@@ -9,13 +9,16 @@ using System.Runtime.InteropServices;
using System.Text;
using System.Text.Encodings.Web;
using System.Threading.Tasks;
using Aliyun.Credentials.Http;
using Aop.Api.Domain;
using Aspose.Cells.Drawing;
using JNPF;
using JNPF.Common.Const;
using JNPF.Common.Contracts;
using JNPF.Common.Core.Manager;
using JNPF.Common.Enums;
using JNPF.Common.Extension;
using JNPF.Common.Manager;
using JNPF.Common.Security;
using JNPF.DependencyInjection;
using JNPF.DynamicApiController;
@@ -59,12 +62,15 @@ namespace Tnb.WarehouseMgr
private readonly IDictionaryDataService _dictionaryDataService;
private readonly IBillRullService _billRullService;
private readonly IUserManager _userManager;
public WareHouseService(ISqlSugarRepository<WmsInstockH> repository, IDictionaryDataService dictionaryDataService, IBillRullService billRullService, IUserManager userManager)
private readonly ICacheManager _cacheManager;
public WareHouseService(ISqlSugarRepository<WmsInstockH> repository, IDictionaryDataService dictionaryDataService, IBillRullService billRullService, IUserManager userManager, ICacheManager cacheManager)
{
_db = repository.AsSugarClient();
_dictionaryDataService = dictionaryDataService;
_billRullService = billRullService;
_userManager = userManager;
_cacheManager = cacheManager;
}
/// <summary>
@@ -221,6 +227,12 @@ namespace Tnb.WarehouseMgr
{
Stopwatch sw = Stopwatch.StartNew();
CancellationTokenSource agvCts = new();
//获取用户登录令牌
var aToken = await _cacheManager.GetAsync("AsscessToken");
if (aToken.IsNullOrWhiteSpace()) return;
var curUser = await GetUserIdentity(aToken);
var db = _db.CopyNew();
try
{
@@ -366,9 +378,18 @@ namespace Tnb.WarehouseMgr
catch (Exception ex)
{
Log.Error("生成预任务执行时出现错误", ex);
var opts = curUser.FindFirst(ClaimConst.CONNECTIONCONFIG)?.Value;
ErrorInfo ei = new()
{
RequestURL = App.HttpContext?.Request?.Path,
RequestMethod = App.HttpContext?.Request?.Method,
userIdentity = curUser,
};
var timedTaskEx = ex.ToTimedTaskException(ei);
await db.Ado.RollbackTranAsync();
cts?.Cancel();
throw;
throw timedTaskEx;
}
finally
{