From 01d70aa8e308a870348d14e8974b3a36d5914fe8 Mon Sep 17 00:00:00 2001
From: cKey <35512826+colinin@users.noreply.github.com>
Date: Fri, 1 Jul 2022 22:26:17 +0800
Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=96=87=E4=BB=B6=E7=B3=BB?=
=?UTF-8?q?=E7=BB=9F=E6=A3=80=E7=B4=A2=E7=B4=A2=E5=BC=95=E5=8F=AF=E8=83=BD?=
=?UTF-8?q?=E8=B6=8A=E7=95=8C=E9=97=AE=E9=A2=98?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
作业异常处理模块无需引用基础作业模块
---
.../FileSystem/FileSystemOssContainer.cs | 12 ++++--
...p.BackgroundTasks.ExceptionHandling.csproj | 2 +-
...pBackgroundTasksExceptionHandlingModule.cs | 6 +--
.../JobFailedNotifierProvider.cs | 40 +++++++++++++++----
4 files changed, 44 insertions(+), 16 deletions(-)
diff --git a/aspnet-core/modules/oss-management/LINGYUN.Abp.OssManagement.FileSystem/LINGYUN/Abp/OssManagement/FileSystem/FileSystemOssContainer.cs b/aspnet-core/modules/oss-management/LINGYUN.Abp.OssManagement.FileSystem/LINGYUN/Abp/OssManagement/FileSystem/FileSystemOssContainer.cs
index 4be7384e2..d12aa2624 100644
--- a/aspnet-core/modules/oss-management/LINGYUN.Abp.OssManagement.FileSystem/LINGYUN/Abp/OssManagement/FileSystem/FileSystemOssContainer.cs
+++ b/aspnet-core/modules/oss-management/LINGYUN.Abp.OssManagement.FileSystem/LINGYUN/Abp/OssManagement/FileSystem/FileSystemOssContainer.cs
@@ -459,10 +459,14 @@ namespace LINGYUN.Abp.OssManagement.FileSystem
.Select(ConvertFileSystem)
.ToArray();
- // 计算下一页起始标记文件/目录名称
- var nextMarkerIndex = fileSystemNames.FindIndex(x => x.EndsWith(fileSystems[fileSystems.Length - 1].Name));
- string nextMarker = "";
- if (nextMarkerIndex >=0 && nextMarkerIndex + 1 < fileSystemNames.Length)
+ var nextMarkerIndex = -1;
+ if (fileSystems.Length > 0)
+ {
+ // 计算下一页起始标记文件/目录名称
+ nextMarkerIndex = fileSystemNames.FindIndex(x => x.EndsWith(fileSystems[^1].Name));
+ }
+ var nextMarker = "";
+ if (nextMarkerIndex >= 0 && nextMarkerIndex + 1 < fileSystemNames.Length)
{
nextMarker = fileSystemNames[nextMarkerIndex + 1];
nextMarker = File.Exists(nextMarker)
diff --git a/aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks.ExceptionHandling/LINGYUN.Abp.BackgroundTasks.ExceptionHandling.csproj b/aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks.ExceptionHandling/LINGYUN.Abp.BackgroundTasks.ExceptionHandling.csproj
index a5dd97fab..45c0aed6a 100644
--- a/aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks.ExceptionHandling/LINGYUN.Abp.BackgroundTasks.ExceptionHandling.csproj
+++ b/aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks.ExceptionHandling/LINGYUN.Abp.BackgroundTasks.ExceptionHandling.csproj
@@ -20,10 +20,10 @@
+
-
diff --git a/aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks.ExceptionHandling/LINGYUN/Abp/BackgroundTasks/ExceptionHandling/AbpBackgroundTasksExceptionHandlingModule.cs b/aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks.ExceptionHandling/LINGYUN/Abp/BackgroundTasks/ExceptionHandling/AbpBackgroundTasksExceptionHandlingModule.cs
index 705a36a01..4e20f436c 100644
--- a/aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks.ExceptionHandling/LINGYUN/Abp/BackgroundTasks/ExceptionHandling/AbpBackgroundTasksExceptionHandlingModule.cs
+++ b/aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks.ExceptionHandling/LINGYUN/Abp/BackgroundTasks/ExceptionHandling/AbpBackgroundTasksExceptionHandlingModule.cs
@@ -1,13 +1,13 @@
-using LINGYUN.Abp.BackgroundTasks.Jobs;
-using LINGYUN.Abp.BackgroundTasks.Localization;
+using LINGYUN.Abp.BackgroundTasks.Localization;
using Volo.Abp.Localization;
using Volo.Abp.Modularity;
+using Volo.Abp.Emailing;
using Volo.Abp.VirtualFileSystem;
namespace LINGYUN.Abp.BackgroundTasks.ExceptionHandling;
[DependsOn(typeof(AbpBackgroundTasksModule))]
-[DependsOn(typeof(AbpBackgroundTasksJobsModule))]
+[DependsOn(typeof(AbpEmailingModule))]
public class AbpBackgroundTasksExceptionHandlingModule : AbpModule
{
public override void ConfigureServices(ServiceConfigurationContext context)
diff --git a/aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks.ExceptionHandling/LINGYUN/Abp/BackgroundTasks/ExceptionHandling/JobFailedNotifierProvider.cs b/aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks.ExceptionHandling/LINGYUN/Abp/BackgroundTasks/ExceptionHandling/JobFailedNotifierProvider.cs
index f1a6abf8a..33791fc93 100644
--- a/aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks.ExceptionHandling/LINGYUN/Abp/BackgroundTasks/ExceptionHandling/JobFailedNotifierProvider.cs
+++ b/aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks.ExceptionHandling/LINGYUN/Abp/BackgroundTasks/ExceptionHandling/JobFailedNotifierProvider.cs
@@ -1,6 +1,5 @@
using JetBrains.Annotations;
using LINGYUN.Abp.BackgroundTasks.ExceptionHandling.Templates;
-using LINGYUN.Abp.BackgroundTasks.Jobs;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging.Abstractions;
using Newtonsoft.Json;
@@ -12,7 +11,6 @@ using Volo.Abp.DependencyInjection;
using Volo.Abp.Emailing;
using Volo.Abp.MultiTenancy;
using Volo.Abp.TextTemplating;
-using Volo.Abp.Timing;
namespace LINGYUN.Abp.BackgroundTasks.ExceptionHandling;
@@ -21,6 +19,32 @@ public class JobFailedNotifierProvider : IJobFailedNotifierProvider, ITransientD
public const string Prefix = "exception.";
public const string JobGroup = "ExceptionNotifier";
+ public const string PropertyFrom = "from";
+ ///
+ /// 接收者
+ ///
+ public const string PropertyTo = "to";
+ ///
+ /// 必须,邮件主体
+ ///
+ public const string PropertySubject = "subject";
+ ///
+ /// 消息内容, 文本消息时必须
+ ///
+ public const string PropertyBody = "body";
+ ///
+ /// 发送模板消息
+ ///
+ public const string PropertyTemplate = "template";
+ ///
+ /// 可选, 模板消息中的上下文参数
+ ///
+ public const string PropertyContext = "context";
+ ///
+ /// 可选, 模板消息中的区域性
+ ///
+ public const string PropertyCulture = "culture";
+
public ILogger Logger { protected get; set; }
protected IEmailSender EmailSender { get; }
@@ -45,13 +69,13 @@ public class JobFailedNotifierProvider : IJobFailedNotifierProvider, ITransientD
Logger.LogWarning($"There is a problem executing the job, reason: {eventData.Exception.Message}");
return;
}
- var notifyKey = Prefix + SendEmailJob.PropertyTo;
+ var notifyKey = Prefix + PropertyTo;
if (eventData.Args.TryGetValue(notifyKey, out var exceptionTo) &&
exceptionTo is string to)
{
- var template = eventData.Args.GetOrDefault(Prefix + SendEmailJob.PropertyTemplate)?.ToString() ?? "";
- var subject = eventData.Args.GetOrDefault(Prefix + SendEmailJob.PropertySubject)?.ToString() ?? "From job execute exception";
- var from = eventData.Args.GetOrDefault(Prefix + SendEmailJob.PropertyFrom)?.ToString() ?? "";
+ var template = eventData.Args.GetOrDefault(Prefix + PropertyTemplate)?.ToString() ?? "";
+ var subject = eventData.Args.GetOrDefault(Prefix + PropertySubject)?.ToString() ?? "From job execute exception";
+ var from = eventData.Args.GetOrDefault(Prefix + PropertyFrom)?.ToString() ?? "";
var errorMessage = eventData.Exception.GetBaseException().Message;
if (template.IsNullOrWhiteSpace())
@@ -78,7 +102,7 @@ public class JobFailedNotifierProvider : IJobFailedNotifierProvider, ITransientD
};
var globalContext = new Dictionary();
- if (eventData.Args.TryGetValue(Prefix + SendEmailJob.PropertyContext, out var ctx) &&
+ if (eventData.Args.TryGetValue(Prefix + PropertyContext, out var ctx) &&
ctx is string ctxStr && !ctxStr.IsNullOrWhiteSpace())
{
try
@@ -89,7 +113,7 @@ public class JobFailedNotifierProvider : IJobFailedNotifierProvider, ITransientD
}
globalContext.AddIfNotContains(eventData.Args);
- var culture = eventData.Args.GetOrDefault(Prefix + SendEmailJob.PropertyCulture)?.ToString() ?? CultureInfo.CurrentCulture.Name;
+ var culture = eventData.Args.GetOrDefault(Prefix + PropertyCulture)?.ToString() ?? CultureInfo.CurrentCulture.Name;
var content = await TemplateRenderer.RenderAsync(
templateName: template,