Browse Source

add background task action: notifications

pull/666/head
cKey 3 years ago
parent
commit
f4627fe64c
  1. 41
      aspnet-core/LINGYUN.MicroService.TaskManagement.sln
  2. 2
      aspnet-core/modules/cli/LINGYUN.Abp.Cli/LINGYUN.Abp.Cli.csproj
  3. 1
      aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks.Abstractions/LINGYUN/Abp/BackgroundTasks/JobActionType.cs
  4. 2
      aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks.ExceptionHandling/LINGYUN/Abp/BackgroundTasks/ExceptionHandling/JobExecutedFailedProvider.cs
  5. 10
      aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks.ExceptionHandling/LINGYUN/Abp/BackgroundTasks/ExceptionHandling/Localization/Resources/zh-Hans.json
  6. 16
      aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks.ExceptionHandling/README.md
  7. 3
      aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks.Notifications/FodyWeavers.xml
  8. 30
      aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks.Notifications/FodyWeavers.xsd
  9. 32
      aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks.Notifications/LINGYUN.Abp.BackgroundTasks.Notifications.csproj
  10. 29
      aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks.Notifications/LINGYUN/Abp/BackgroundTasks/Notifications/AbpBackgroundTasksNotificationsModule.cs
  11. 51
      aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks.Notifications/LINGYUN/Abp/BackgroundTasks/Notifications/BackgroundTasksNotificationDefinitionProvider.cs
  12. 18
      aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks.Notifications/LINGYUN/Abp/BackgroundTasks/Notifications/BackgroundTasksNotificationNames.cs
  13. 31
      aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks.Notifications/LINGYUN/Abp/BackgroundTasks/Notifications/JobExecuteCompletedNotificationProvider.cs
  14. 31
      aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks.Notifications/LINGYUN/Abp/BackgroundTasks/Notifications/JobExecuteFailedNotificationProvider.cs
  15. 31
      aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks.Notifications/LINGYUN/Abp/BackgroundTasks/Notifications/JobExecutedSuccessedNotificationProvider.cs
  16. 22
      aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks.Notifications/LINGYUN/Abp/BackgroundTasks/Notifications/Localization/Resources/en.json
  17. 22
      aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks.Notifications/LINGYUN/Abp/BackgroundTasks/Notifications/Localization/Resources/zh-Hans.json
  18. 41
      aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks.Notifications/LINGYUN/Abp/BackgroundTasks/Notifications/NotificationJobActionDefinitionProvider.cs
  19. 108
      aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks.Notifications/LINGYUN/Abp/BackgroundTasks/Notifications/NotificationJobExecutedProvider.cs
  20. 24
      aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks.Notifications/README.md
  21. 1
      aspnet-core/services/LY.MicroService.TaskManagement.HttpApi.Host/LY.MicroService.TaskManagement.HttpApi.Host.csproj
  22. 2
      aspnet-core/services/LY.MicroService.TaskManagement.HttpApi.Host/TaskManagementHttpApiHostModule.cs

41
aspnet-core/LINGYUN.MicroService.TaskManagement.sln

@ -52,7 +52,21 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LINGYUN.Abp.BackgroundTasks
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "extend-jobs", "extend-jobs", "{A9536BD2-2573-44CA-B033-DC16B7E345E5}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LINGYUN.Abp.Notifications.Jobs", "modules\common\LINGYUN.Abp.Notifications.Jobs\LINGYUN.Abp.Notifications.Jobs.csproj", "{17D7ED0F-E789-4637-9B06-57DF693C6E1E}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LINGYUN.Abp.Notifications.Jobs", "modules\common\LINGYUN.Abp.Notifications.Jobs\LINGYUN.Abp.Notifications.Jobs.csproj", "{17D7ED0F-E789-4637-9B06-57DF693C6E1E}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LINGYUN.Abp.BackgroundTasks.Notifications", "modules\task-management\LINGYUN.Abp.BackgroundTasks.Notifications\LINGYUN.Abp.BackgroundTasks.Notifications.csproj", "{1978B64C-B2F5-4F68-9E5C-B45F948E7155}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "realtime", "realtime", "{18918B94-BB48-48F3-874D-B91B0252440A}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LINGYUN.Abp.RealTime", "modules\common\LINGYUN.Abp.RealTime\LINGYUN.Abp.RealTime.csproj", "{23620224-93A1-4A88-93B7-23D37929FCF7}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LINGYUN.Abp.Notifications", "modules\common\LINGYUN.Abp.Notifications\LINGYUN.Abp.Notifications.csproj", "{09F7171C-6DA1-4466-AB4A-DC92E93368EC}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "dapr", "dapr", "{FA5E30C9-05E3-4E35-AEDD-7DC5534E3A01}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LINGYUN.Abp.Dapr", "modules\dapr\LINGYUN.Abp.Dapr\LINGYUN.Abp.Dapr.csproj", "{2FA23894-E598-4896-A336-3E7C682699D9}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LINGYUN.Abp.Dapr.Client", "modules\dapr\LINGYUN.Abp.Dapr.Client\LINGYUN.Abp.Dapr.Client.csproj", "{194DAB61-BC3C-4003-BFF0-C87763E7B8B0}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@ -132,6 +146,26 @@ Global
{17D7ED0F-E789-4637-9B06-57DF693C6E1E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{17D7ED0F-E789-4637-9B06-57DF693C6E1E}.Release|Any CPU.ActiveCfg = Release|Any CPU
{17D7ED0F-E789-4637-9B06-57DF693C6E1E}.Release|Any CPU.Build.0 = Release|Any CPU
{1978B64C-B2F5-4F68-9E5C-B45F948E7155}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{1978B64C-B2F5-4F68-9E5C-B45F948E7155}.Debug|Any CPU.Build.0 = Debug|Any CPU
{1978B64C-B2F5-4F68-9E5C-B45F948E7155}.Release|Any CPU.ActiveCfg = Release|Any CPU
{1978B64C-B2F5-4F68-9E5C-B45F948E7155}.Release|Any CPU.Build.0 = Release|Any CPU
{23620224-93A1-4A88-93B7-23D37929FCF7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{23620224-93A1-4A88-93B7-23D37929FCF7}.Debug|Any CPU.Build.0 = Debug|Any CPU
{23620224-93A1-4A88-93B7-23D37929FCF7}.Release|Any CPU.ActiveCfg = Release|Any CPU
{23620224-93A1-4A88-93B7-23D37929FCF7}.Release|Any CPU.Build.0 = Release|Any CPU
{09F7171C-6DA1-4466-AB4A-DC92E93368EC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{09F7171C-6DA1-4466-AB4A-DC92E93368EC}.Debug|Any CPU.Build.0 = Debug|Any CPU
{09F7171C-6DA1-4466-AB4A-DC92E93368EC}.Release|Any CPU.ActiveCfg = Release|Any CPU
{09F7171C-6DA1-4466-AB4A-DC92E93368EC}.Release|Any CPU.Build.0 = Release|Any CPU
{2FA23894-E598-4896-A336-3E7C682699D9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{2FA23894-E598-4896-A336-3E7C682699D9}.Debug|Any CPU.Build.0 = Debug|Any CPU
{2FA23894-E598-4896-A336-3E7C682699D9}.Release|Any CPU.ActiveCfg = Release|Any CPU
{2FA23894-E598-4896-A336-3E7C682699D9}.Release|Any CPU.Build.0 = Release|Any CPU
{194DAB61-BC3C-4003-BFF0-C87763E7B8B0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{194DAB61-BC3C-4003-BFF0-C87763E7B8B0}.Debug|Any CPU.Build.0 = Debug|Any CPU
{194DAB61-BC3C-4003-BFF0-C87763E7B8B0}.Release|Any CPU.ActiveCfg = Release|Any CPU
{194DAB61-BC3C-4003-BFF0-C87763E7B8B0}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
@ -155,6 +189,11 @@ Global
{A817B7B7-A225-404A-A301-B42D400DE4B7} = {C38EB7EF-BAE9-4129-862A-71C652B81775}
{3D0A1901-36FB-4DA2-9F8D-05308598E98C} = {C38EB7EF-BAE9-4129-862A-71C652B81775}
{17D7ED0F-E789-4637-9B06-57DF693C6E1E} = {A9536BD2-2573-44CA-B033-DC16B7E345E5}
{1978B64C-B2F5-4F68-9E5C-B45F948E7155} = {C38EB7EF-BAE9-4129-862A-71C652B81775}
{23620224-93A1-4A88-93B7-23D37929FCF7} = {18918B94-BB48-48F3-874D-B91B0252440A}
{09F7171C-6DA1-4466-AB4A-DC92E93368EC} = {18918B94-BB48-48F3-874D-B91B0252440A}
{2FA23894-E598-4896-A336-3E7C682699D9} = {FA5E30C9-05E3-4E35-AEDD-7DC5534E3A01}
{194DAB61-BC3C-4003-BFF0-C87763E7B8B0} = {FA5E30C9-05E3-4E35-AEDD-7DC5534E3A01}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {E1FD1F4C-D344-408B-97CF-B6F1F6D7D293}

2
aspnet-core/modules/cli/LINGYUN.Abp.Cli/LINGYUN.Abp.Cli.csproj

@ -5,7 +5,7 @@
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<Version>5.3.2</Version>
<Version>5.3.4</Version>
<Copyright>colin</Copyright>
<Description>Use LINGYUN.MicroService.Templates command line</Description>
<PackAsTool>true</PackAsTool>

1
aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks.Abstractions/LINGYUN/Abp/BackgroundTasks/JobActionType.cs

@ -4,4 +4,5 @@ public enum JobActionType
{
Failed = -1,
Successed = 0,
Completed = 1,
}

2
aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks.ExceptionHandling/LINGYUN/Abp/BackgroundTasks/ExceptionHandling/JobExecutedFailedProvider.cs

@ -103,7 +103,7 @@ public class JobExecutedFailedProvider : JobExecutedProvider, ITransientDependen
Type = context.Event.EventData.Args.GetOrDefault(nameof(JobInfo.Type)) ?? context.Event.EventData.Type.Name,
Triggertime = context.Event.EventData.RunTime.ToString("yyyy-MM-dd HH:mm:ss"),
Message = errorMessage,
Tenantname = context.Action.Paramters.GetOrDefault(nameof(IMultiTenant.TenantId)),
Tenantname = context.Event.EventData.Args.GetOrDefault(nameof(IMultiTenant.TenantId)),
Footer = footer,
};

10
aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks.ExceptionHandling/LINGYUN/Abp/BackgroundTasks/ExceptionHandling/Localization/Resources/zh-Hans.json

@ -6,17 +6,17 @@
"DisplayName:To": "收件方",
"Description:To": "demo@example.com, 多个接收者以逗号分隔.",
"DisplayName:Subject": "邮件标题",
"Description:Subject": "发送邮件的标题",
"Description:Subject": "发送邮件的标题.",
"DisplayName:From": "发送方",
"Description:From": "邮件发送方名称",
"Description:From": "邮件发送方名称.",
"DisplayName:Body": "内容",
"Description:Body": "发送的文本内容.",
"DisplayName:Template": "模板名称",
"Description:Template": "如需指定模板内容则指定.",
"Description:Template": "如果指定模板名称,将发送格式化模板消息.",
"DisplayName:Context": "上下文参数",
"Description:Context": "格式化模板内容时指定.",
"Description:Context": "格式化模板内容时指定参数.",
"DisplayName:Culture": "文化名称",
"Description:Culture": "需要本地化邮件内容指定",
"Description:Culture": "需要本地化内容指定.",
"TenantName": "租户名称",
"JobGroup": "作业分组",
"JobName": "作业名称",

16
aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks.ExceptionHandling/README.md

@ -14,14 +14,14 @@ public class YouProjectModule : AbpModule
}
```
## 先决条件
## Action参数
** 在定义作业时在参数中指定如下参数,在作业执行失败时将发送通知
* exception.to 必须, 接收者邮件地址
* exception.from 可选, 邮件抬头发送者名称
* exception.body 可选, 邮件内容(未指定模板名称则为必须参数)
* exception.subject 可选, 邮件标题
* exception.template 可选, 邮件模板
* exception.context 可选, 使用模板时的上下文参数
* exception.culture 可选, 使用模板时的模板区域性
* to 必须, 接收者邮件地址
* from 可选, 邮件抬头发送者名称
* body 可选, 邮件内容(未指定模板名称则为必须参数)
* subject 可选, 邮件标题
* template 可选, 邮件模板
* context 可选, 使用模板时的上下文参数
* culture 可选, 使用模板时的模板区域性

3
aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks.Notifications/FodyWeavers.xml

@ -0,0 +1,3 @@
<Weavers xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="FodyWeavers.xsd">
<ConfigureAwait ContinueOnCapturedContext="false" />
</Weavers>

30
aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks.Notifications/FodyWeavers.xsd

@ -0,0 +1,30 @@
<?xml version="1.0" encoding="utf-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<!-- This file was generated by Fody. Manual changes to this file will be lost when your project is rebuilt. -->
<xs:element name="Weavers">
<xs:complexType>
<xs:all>
<xs:element name="ConfigureAwait" minOccurs="0" maxOccurs="1">
<xs:complexType>
<xs:attribute name="ContinueOnCapturedContext" type="xs:boolean" />
</xs:complexType>
</xs:element>
</xs:all>
<xs:attribute name="VerifyAssembly" type="xs:boolean">
<xs:annotation>
<xs:documentation>'true' to run assembly verification (PEVerify) on the target assembly after all weavers have been executed.</xs:documentation>
</xs:annotation>
</xs:attribute>
<xs:attribute name="VerifyIgnoreCodes" type="xs:string">
<xs:annotation>
<xs:documentation>A comma-separated list of error codes that can be safely ignored in assembly verification.</xs:documentation>
</xs:annotation>
</xs:attribute>
<xs:attribute name="GenerateXsd" type="xs:boolean">
<xs:annotation>
<xs:documentation>'false' to turn off automatic generation of the XML Schema file.</xs:documentation>
</xs:annotation>
</xs:attribute>
</xs:complexType>
</xs:element>
</xs:schema>

32
aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks.Notifications/LINGYUN.Abp.BackgroundTasks.Notifications.csproj

@ -0,0 +1,32 @@
<Project Sdk="Microsoft.NET.Sdk">
<Import Project="..\..\..\configureawait.props" />
<Import Project="..\..\..\common.props" />
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<RootNamespace />
</PropertyGroup>
<ItemGroup>
<None Remove="LINGYUN\Abp\BackgroundTasks\Notifications\Localization\Resources\*.json" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="LINGYUN\Abp\BackgroundTasks\Notifications\Localization\Resources\*.json" />
</ItemGroup>
<ItemGroup>
<None Remove="LINGYUN\Abp\BackgroundTasks\Notifications\Templates\JobExecutedNotification.tpl" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="LINGYUN\Abp\BackgroundTasks\Notifications\Templates\JobExecutedNotification.tpl" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\common\LINGYUN.Abp.Notifications\LINGYUN.Abp.Notifications.csproj" />
<ProjectReference Include="..\LINGYUN.Abp.BackgroundTasks.Activities\LINGYUN.Abp.BackgroundTasks.Activities.csproj" />
</ItemGroup>
</Project>

29
aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks.Notifications/LINGYUN/Abp/BackgroundTasks/Notifications/AbpBackgroundTasksNotificationsModule.cs

@ -0,0 +1,29 @@
using LINGYUN.Abp.BackgroundTasks.Activities;
using LINGYUN.Abp.BackgroundTasks.Localization;
using LINGYUN.Abp.Notifications;
using Volo.Abp.Localization;
using Volo.Abp.Modularity;
using Volo.Abp.VirtualFileSystem;
namespace LINGYUN.Abp.BackgroundTasks.Notifications;
[DependsOn(
typeof(AbpBackgroundTasksActivitiesModule),
typeof(AbpNotificationModule))]
public class AbpBackgroundTasksNotificationsModule : AbpModule
{
public override void ConfigureServices(ServiceConfigurationContext context)
{
Configure<AbpVirtualFileSystemOptions>(options =>
{
options.FileSets.AddEmbedded<AbpBackgroundTasksNotificationsModule>();
});
Configure<AbpLocalizationOptions>(options =>
{
options.Resources
.Get<BackgroundTasksResource>()
.AddVirtualJson("/LINGYUN/Abp/BackgroundTasks/Notifications/Localization/Resources");
});
}
}

51
aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks.Notifications/LINGYUN/Abp/BackgroundTasks/Notifications/BackgroundTasksNotificationDefinitionProvider.cs

@ -0,0 +1,51 @@
using LINGYUN.Abp.BackgroundTasks.Localization;
using LINGYUN.Abp.Notifications;
using Volo.Abp.Localization;
namespace LINGYUN.Abp.BackgroundTasks.Notifications;
public class BackgroundTasksNotificationDefinitionProvider : NotificationDefinitionProvider
{
public override void Define(INotificationDefinitionContext context)
{
var backgroundTaskGroup = context.AddGroup(
BackgroundTasksNotificationNames.GroupName,
L("Notifications:BackgroundTasks"));
backgroundTaskGroup.AddNotification(
BackgroundTasksNotificationNames.JobExecuteSucceeded,
L("Notifications:JobExecuteSucceeded"),
L("Notifications:JobExecuteSucceededDesc"),
notificationType: NotificationType.Application,
lifetime: NotificationLifetime.Persistent,
allowSubscriptionToClients: true)
.WithProviders(
NotificationProviderNames.SignalR,
NotificationProviderNames.Emailing);
backgroundTaskGroup.AddNotification(
BackgroundTasksNotificationNames.JobExecuteFailed,
L("Notifications:JobExecuteFailed"),
L("Notifications:JobExecuteFailedDesc"),
notificationType: NotificationType.Application,
lifetime: NotificationLifetime.Persistent,
allowSubscriptionToClients: true)
.WithProviders(
NotificationProviderNames.SignalR,
NotificationProviderNames.Emailing);
backgroundTaskGroup.AddNotification(
BackgroundTasksNotificationNames.JobExecuteCompleted,
L("Notifications:JobExecuteCompleted"),
L("Notifications:JobExecuteCompletedDesc"),
notificationType: NotificationType.Application,
lifetime: NotificationLifetime.Persistent,
allowSubscriptionToClients: true)
.WithProviders(
NotificationProviderNames.SignalR,
NotificationProviderNames.Emailing);
}
protected LocalizableString L(string name)
{
return LocalizableString.Create<BackgroundTasksResource>(name);
}
}

18
aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks.Notifications/LINGYUN/Abp/BackgroundTasks/Notifications/BackgroundTasksNotificationNames.cs

@ -0,0 +1,18 @@
namespace LINGYUN.Abp.BackgroundTasks.Notifications;
public static class BackgroundTasksNotificationNames
{
public const string GroupName = "Abp.Notifications.BackgroundTasks";
/// <summary>
/// 作业执行成功
/// </summary>
public const string JobExecuteSucceeded = GroupName + ".ExecuteSucceeded";
/// <summary>
/// 作业执行失败
/// </summary>
public const string JobExecuteFailed = GroupName + ".ExecuteFailed";
/// <summary>
/// 作业执行完毕
/// </summary>
public const string JobExecuteCompleted = GroupName + ".ExecuteCompleted";
}

31
aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks.Notifications/LINGYUN/Abp/BackgroundTasks/Notifications/JobExecuteCompletedNotificationProvider.cs

@ -0,0 +1,31 @@
using JetBrains.Annotations;
using LINGYUN.Abp.BackgroundTasks.Activities;
using LINGYUN.Abp.BackgroundTasks.Localization;
using LINGYUN.Abp.Notifications;
using Microsoft.Extensions.Localization;
using System.Threading.Tasks;
using Volo.Abp.MultiTenancy;
using Volo.Abp.TextTemplating;
namespace LINGYUN.Abp.BackgroundTasks.Notifications;
public class JobExecuteCompletedNotificationProvider : NotificationJobExecutedProvider
{
public const string Name = "JobExecutedCompletedNofiter";
public JobExecuteCompletedNotificationProvider(
ICurrentTenant currentTenant,
INotificationSender notificationSender,
ITemplateRenderer templateRenderer,
IStringLocalizer<BackgroundTasksResource> stringLocalizer)
: base(currentTenant, notificationSender, templateRenderer, stringLocalizer)
{
}
public async override Task NotifyComplateAsync([NotNull] JobActionExecuteContext context)
{
var title = StringLocalizer["JobExecutedCompleted"].Value;
await SendNofiterAsync(context, title, NotificationSeverity.Info);
}
}

31
aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks.Notifications/LINGYUN/Abp/BackgroundTasks/Notifications/JobExecuteFailedNotificationProvider.cs

@ -0,0 +1,31 @@
using JetBrains.Annotations;
using LINGYUN.Abp.BackgroundTasks.Activities;
using LINGYUN.Abp.BackgroundTasks.Localization;
using LINGYUN.Abp.Notifications;
using Microsoft.Extensions.Localization;
using System.Threading.Tasks;
using Volo.Abp.MultiTenancy;
using Volo.Abp.TextTemplating;
namespace LINGYUN.Abp.BackgroundTasks.Notifications;
public class JobExecuteFailedNotificationProvider : NotificationJobExecutedProvider
{
public const string Name = "JobExecutedFailedNofiter";
public JobExecuteFailedNotificationProvider(
ICurrentTenant currentTenant,
INotificationSender notificationSender,
ITemplateRenderer templateRenderer,
IStringLocalizer<BackgroundTasksResource> stringLocalizer)
: base(currentTenant, notificationSender, templateRenderer, stringLocalizer)
{
}
public async override Task NotifyErrorAsync([NotNull] JobActionExecuteContext context)
{
var title = StringLocalizer["JobExecutedFailed"].Value;
await SendNofiterAsync(context, title, NotificationSeverity.Error);
}
}

31
aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks.Notifications/LINGYUN/Abp/BackgroundTasks/Notifications/JobExecutedSuccessedNotificationProvider.cs

@ -0,0 +1,31 @@
using JetBrains.Annotations;
using LINGYUN.Abp.BackgroundTasks.Activities;
using LINGYUN.Abp.BackgroundTasks.Localization;
using LINGYUN.Abp.Notifications;
using Microsoft.Extensions.Localization;
using System.Threading.Tasks;
using Volo.Abp.MultiTenancy;
using Volo.Abp.TextTemplating;
namespace LINGYUN.Abp.BackgroundTasks.Notifications;
public class JobExecutedSuccessedNotificationProvider : NotificationJobExecutedProvider
{
public const string Name = "JobExecutedSuccessedNofiter";
public JobExecutedSuccessedNotificationProvider(
ICurrentTenant currentTenant,
INotificationSender notificationSender,
ITemplateRenderer templateRenderer,
IStringLocalizer<BackgroundTasksResource> stringLocalizer)
: base(currentTenant, notificationSender, templateRenderer, stringLocalizer)
{
}
public async override Task NotifySuccessAsync([NotNull] JobActionExecuteContext context)
{
var title = StringLocalizer["JobExecutedSucceeded"].Value;
await SendNofiterAsync(context, title, NotificationSeverity.Success);
}
}

22
aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks.Notifications/LINGYUN/Abp/BackgroundTasks/Notifications/Localization/Resources/en.json

@ -0,0 +1,22 @@
{
"culture": "en",
"texts": {
"Notifications:BackgroundTasks": "Background job Notification",
"Notifications:JobExecuteSucceeded": "Job Success Notification",
"Notifications:JobExecuteSucceededDesc": "After the background job is successfully executed, the notification is pushed.",
"Notifications:JobExecuteFailed": "Job Failure Notification",
"Notifications:JobExecuteFailedDesc": "Notification push after the execution of a background job failed.",
"Notifications:JobExecuteCompleted": "Job Completed Notification",
"Notifications:JobExecuteCompletedDesc": "After the background job is complated, the notification is pushed.",
"DisplayName:PushProvider": "Push Service Provider",
"Description:PushProvider": "If a push program is specified, the application will select it to push messages. The optional list is :SignalR(real-time notification), Sms(Sms notification), Emailing(email notification), wecht.miniprogram (WeChat MiniProgram), WxPusher(WxPusher WeChat push service), PushPlus (PushPlus multi-platform push service).",
"DisplayName:Template": "Template",
"Description:Template": "If the template content needs to be specified.",
"DisplayName:Context": "Context",
"Description:Context": "Specified when formatting template content.",
"DisplayName:Content": "Content",
"Description:Content": "If you specify the content, a plain text message is sent.",
"DisplayName:Culture": "Culture",
"Description:Culture": "Need to localize the message content specification"
}
}

22
aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks.Notifications/LINGYUN/Abp/BackgroundTasks/Notifications/Localization/Resources/zh-Hans.json

@ -0,0 +1,22 @@
{
"culture": "zh-Hans",
"texts": {
"Notifications:BackgroundTasks": "后台作业通知",
"Notifications:JobExecuteSucceeded": "作业成功通知",
"Notifications:JobExecuteSucceededDesc": "后台作业执行成功后通知推送.",
"Notifications:JobExecuteFailed": "作业失败通知",
"Notifications:JobExecuteFailedDesc": "后台作业执行失败后通知推送.",
"Notifications:JobExecuteCompleted": "作业完成通知",
"Notifications:JobExecuteCompletedDesc": "后台作业执行完成后通知推送.",
"DisplayName:PushProvider": "推送程序",
"Description:PushProvider": "如果指定推送程序,应用将选择它进行消息推送,可选列表:SignalR(实时通知)、Sms(短信通知)、Emailing(邮件通知)、WeChat.MiniProgram(微信小程序)、WxPusher(WxPusher微信推送服务)、PushPlus(PushPlus多平台推送服务)",
"DisplayName:Template": "模板名称",
"Description:Template": "如果指定模板名称,将发送格式化模板消息.",
"DisplayName:Context": "上下文参数",
"Description:Context": "格式化模板内容时指定参数.",
"DisplayName:Content": "内容",
"Description:Content": "如果指定内容,将发送普通文本消息.",
"DisplayName:Culture": "文化名称",
"Description:Culture": "需要本地化内容指定."
}
}

41
aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks.Notifications/LINGYUN/Abp/BackgroundTasks/Notifications/NotificationJobActionDefinitionProvider.cs

@ -0,0 +1,41 @@
using LINGYUN.Abp.BackgroundTasks.Activities;
using LINGYUN.Abp.BackgroundTasks.Localization;
using Volo.Abp.Localization;
namespace LINGYUN.Abp.BackgroundTasks.Notifications;
public class NotificationJobActionDefinitionProvider : JobActionDefinitionProvider
{
public override void Define(IJobActionDefinitionContext context)
{
context.Add(
new JobActionDefinition(
JobExecutedSuccessedNotificationProvider.Name,
JobActionType.Successed,
L("Notifications:JobExecuteSucceeded"),
NotificationJobExecutedProvider.Paramters,
L("Notifications:JobExecuteSucceededDesc"))
.WithProvider<JobExecutedSuccessedNotificationProvider>());
context.Add(
new JobActionDefinition(
JobExecuteFailedNotificationProvider.Name,
JobActionType.Failed,
L("Notifications:JobExecuteFailed"),
NotificationJobExecutedProvider.Paramters,
L("Notifications:JobExecuteFailedDesc"))
.WithProvider<JobExecuteFailedNotificationProvider>());
context.Add(
new JobActionDefinition(
JobExecuteCompletedNotificationProvider.Name,
JobActionType.Completed,
L("Notifications:JobExecuteCompleted"),
NotificationJobExecutedProvider.Paramters,
L("Notifications:JobExecuteCompletedDesc"))
.WithProvider<JobExecuteCompletedNotificationProvider>());
}
private static ILocalizableString L(string name)
{
return LocalizableString.Create<BackgroundTasksResource>(name);
}
}

108
aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks.Notifications/LINGYUN/Abp/BackgroundTasks/Notifications/NotificationJobExecutedProvider.cs

@ -0,0 +1,108 @@
using JetBrains.Annotations;
using LINGYUN.Abp.BackgroundTasks.Activities;
using LINGYUN.Abp.BackgroundTasks.Localization;
using LINGYUN.Abp.Notifications;
using Microsoft.Extensions.Localization;
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Threading.Tasks;
using Volo.Abp.DependencyInjection;
using Volo.Abp.Localization;
using Volo.Abp.MultiTenancy;
using Volo.Abp.TextTemplating;
namespace LINGYUN.Abp.BackgroundTasks.Notifications;
public abstract class NotificationJobExecutedProvider : JobExecutedProvider, ITransientDependency
{
public readonly static IList<JobActionParamter> Paramters = new List<JobActionParamter>
{
new JobActionParamter(PropertyPushProvider, L("DisplayName:PushProvider"), L("Description:PushProvider")),
new JobActionParamter(PropertyUseTemplate, L("DisplayName:Template"), L("Description:Template")),
new JobActionParamter(PropertyContent, L("DisplayName:Content"), L("Description:Content")),
new JobActionParamter(PropertyCulture, L("DisplayName:Culture"), L("Description:Culture")),
};
/// <summary>
/// 指定发送工具
/// </summary>
public const string PropertyPushProvider = "push-provider";
/// <summary>
/// 使用通知模板
/// </summary>
public const string PropertyUseTemplate = "use-template";
/// <summary>
/// 通知内容, 不使用模板时必须
/// </summary>
public const string PropertyContent = "content";
/// <summary>
/// 可选, 模板消息中的区域性
/// </summary>
public const string PropertyCulture = "culture";
protected ICurrentTenant CurrentTenant { get; }
protected INotificationSender NotificationSender { get; }
protected ITemplateRenderer TemplateRenderer { get; }
protected IStringLocalizer<BackgroundTasksResource> StringLocalizer { get; }
protected NotificationJobExecutedProvider(
ICurrentTenant currentTenant,
INotificationSender notificationSender,
ITemplateRenderer templateRenderer,
IStringLocalizer<BackgroundTasksResource> stringLocalizer)
{
CurrentTenant = currentTenant;
NotificationSender = notificationSender;
TemplateRenderer = templateRenderer;
StringLocalizer = stringLocalizer;
}
protected async virtual Task SendNofiterAsync(
[NotNull] JobActionExecuteContext context,
[NotNull] string title,
NotificationSeverity severity = NotificationSeverity.Info)
{
var content = context.Action.Paramters.GetOrDefault(PropertyContent)?.ToString() ?? "";
var templateName = context.Action.Paramters.GetOrDefault(PropertyUseTemplate)?.ToString()
?? BackgroundTasksNotificationNames.JobExecuteSucceeded;
if (content.IsNullOrWhiteSpace() && !templateName.IsNullOrWhiteSpace())
{
var errorMessage = context.Event.EventData.Exception?.GetBaseException().Message;
var model = new
{
Error = context.Event.EventData.Exception != null,
Errormessage = errorMessage,
Title = title,
Id = context.Event.EventData.Key,
Group = context.Event.EventData.Args.GetOrDefault(nameof(JobInfo.Group)) ?? context.Event.EventData.Group,
Name = context.Event.EventData.Args.GetOrDefault(nameof(JobInfo.Name)) ?? context.Event.EventData.Name,
Type = context.Event.EventData.Args.GetOrDefault(nameof(JobInfo.Type)) ?? context.Event.EventData.Type.Name,
Triggertime = context.Event.EventData.RunTime.ToString("yyyy-MM-dd HH:mm:ss"),
Tenantname = context.Event.EventData.Args.GetOrDefault(nameof(IMultiTenant.TenantId)),
};
var culture = context.Action.Paramters.GetOrDefault(PropertyCulture)?.ToString() ?? CultureInfo.CurrentCulture.Name;
content = await TemplateRenderer.RenderAsync(templateName, model, culture);
}
var notificationData = new NotificationData();
notificationData.WriteStandardData(
title: title,
message: content,
createTime: context.Event.EventData.RunTime,
formUser: "BackgroundTasks Engine");
await NotificationSender.SendNofiterAsync(
BackgroundTasksNotificationNames.JobExecuteSucceeded,
notificationData,
tenantId: CurrentTenant.Id,
severity: severity);
}
private static ILocalizableString L(string name)
{
return LocalizableString.Create<BackgroundTasksResource>(name);
}
}

24
aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks.Notifications/README.md

@ -0,0 +1,24 @@
# LINGYUN.Abp.BackgroundTasks.Notifications
后台作业执行后通知事件
## 配置使用
模块按需引用
```csharp
[DependsOn(typeof(AbpBackgroundTasksNotificationsModule))]
public class YouProjectModule : AbpModule
{
// other
}
```
## Action参数
** 通知内容格式化参数,在作业后将发送实时通知
* push-provider 可选, 用户指定消息推送提供程序;
* use-template 可选, 用于格式化通知内容的模板名称
* content 可选, 通知内容(未指定模板名称则为必须参数)
* culture 可选, 使用模板时的模板区域性

1
aspnet-core/services/LY.MicroService.TaskManagement.HttpApi.Host/LY.MicroService.TaskManagement.HttpApi.Host.csproj

@ -61,6 +61,7 @@
<ProjectReference Include="..\..\modules\task-management\LINGYUN.Abp.BackgroundTasks.DistributedLocking\LINGYUN.Abp.BackgroundTasks.DistributedLocking.csproj" />
<ProjectReference Include="..\..\modules\task-management\LINGYUN.Abp.BackgroundTasks.ExceptionHandling\LINGYUN.Abp.BackgroundTasks.ExceptionHandling.csproj" />
<ProjectReference Include="..\..\modules\task-management\LINGYUN.Abp.BackgroundTasks.Jobs\LINGYUN.Abp.BackgroundTasks.Jobs.csproj" />
<ProjectReference Include="..\..\modules\task-management\LINGYUN.Abp.BackgroundTasks.Notifications\LINGYUN.Abp.BackgroundTasks.Notifications.csproj" />
<ProjectReference Include="..\..\modules\task-management\LINGYUN.Abp.BackgroundTasks.Quartz\LINGYUN.Abp.BackgroundTasks.Quartz.csproj" />
<ProjectReference Include="..\..\modules\task-management\LINGYUN.Abp.TaskManagement.Application\LINGYUN.Abp.TaskManagement.Application.csproj" />
<ProjectReference Include="..\..\modules\task-management\LINGYUN.Abp.TaskManagement.EntityFrameworkCore\LINGYUN.Abp.TaskManagement.EntityFrameworkCore.csproj" />

2
aspnet-core/services/LY.MicroService.TaskManagement.HttpApi.Host/TaskManagementHttpApiHostModule.cs

@ -5,6 +5,7 @@ using LINGYUN.Abp.Authorization.OrganizationUnits;
using LINGYUN.Abp.BackgroundTasks.DistributedLocking;
using LINGYUN.Abp.BackgroundTasks.ExceptionHandling;
using LINGYUN.Abp.BackgroundTasks.Jobs;
using LINGYUN.Abp.BackgroundTasks.Notifications;
using LINGYUN.Abp.BackgroundTasks.Quartz;
using LINGYUN.Abp.Data.DbMigrator;
using LINGYUN.Abp.EventBus.CAP;
@ -55,6 +56,7 @@ namespace LY.MicroService.TaskManagement;
typeof(AbpBackgroundTasksQuartzModule),
typeof(AbpBackgroundTasksDistributedLockingModule),
typeof(AbpBackgroundTasksExceptionHandlingModule),
typeof(AbpBackgroundTasksNotificationsModule),
typeof(TaskManagementApplicationModule),
typeof(TaskManagementHttpApiModule),
typeof(TaskManagementEntityFrameworkCoreModule),

Loading…
Cancel
Save