Browse Source

Merge pull request #1290 from colinin/custom-task-action

feat(tasks): Allow users to customize job notifications
pull/1312/head
yx lin 8 months ago
committed by GitHub
parent
commit
e885115eca
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 3
      aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks.Notifications/LINGYUN/Abp/BackgroundTasks/Notifications/JobExecuteCompletedNotificationProvider.cs
  2. 3
      aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks.Notifications/LINGYUN/Abp/BackgroundTasks/Notifications/JobExecuteFailedNotificationProvider.cs
  3. 3
      aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks.Notifications/LINGYUN/Abp/BackgroundTasks/Notifications/JobExecutedSuccessedNotificationProvider.cs
  4. 2
      aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks.Notifications/LINGYUN/Abp/BackgroundTasks/Notifications/Localization/Resources/en.json
  5. 2
      aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks.Notifications/LINGYUN/Abp/BackgroundTasks/Notifications/Localization/Resources/zh-Hans.json
  6. 16
      aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks.Notifications/LINGYUN/Abp/BackgroundTasks/Notifications/NotificationJobExecutedProvider.cs

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

@ -12,6 +12,7 @@ namespace LINGYUN.Abp.BackgroundTasks.Notifications;
public class JobExecuteCompletedNotificationProvider : NotificationJobExecutedProvider
{
public const string Name = "JobExecutedCompletedNofiter";
public override string DefaultNotificationName => BackgroundTasksNotificationNames.JobExecuteCompleted;
public JobExecuteCompletedNotificationProvider(
ICurrentTenant currentTenant,
@ -24,7 +25,7 @@ public class JobExecuteCompletedNotificationProvider : NotificationJobExecutedPr
public async override Task NotifyComplateAsync([NotNull] JobActionExecuteContext context)
{
var title = StringLocalizer["JobExecutedCompleted"].Value;
var title = StringLocalizer["Notifications:JobExecuteCompleted"].Value;
await SendNofiterAsync(context, title, NotificationSeverity.Info);
}

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

@ -12,6 +12,7 @@ namespace LINGYUN.Abp.BackgroundTasks.Notifications;
public class JobExecuteFailedNotificationProvider : NotificationJobExecutedProvider
{
public const string Name = "JobExecutedFailedNofiter";
public override string DefaultNotificationName => BackgroundTasksNotificationNames.JobExecuteFailed;
public JobExecuteFailedNotificationProvider(
ICurrentTenant currentTenant,
@ -24,7 +25,7 @@ public class JobExecuteFailedNotificationProvider : NotificationJobExecutedProvi
public async override Task NotifyErrorAsync([NotNull] JobActionExecuteContext context)
{
var title = StringLocalizer["JobExecutedFailed"].Value;
var title = StringLocalizer["Notifications:JobExecuteFailed"].Value;
await SendNofiterAsync(context, title, NotificationSeverity.Error);
}

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

@ -12,6 +12,7 @@ namespace LINGYUN.Abp.BackgroundTasks.Notifications;
public class JobExecutedSuccessedNotificationProvider : NotificationJobExecutedProvider
{
public const string Name = "JobExecutedSuccessedNofiter";
public override string DefaultNotificationName => BackgroundTasksNotificationNames.JobExecuteSucceeded;
public JobExecutedSuccessedNotificationProvider(
ICurrentTenant currentTenant,
@ -24,7 +25,7 @@ public class JobExecutedSuccessedNotificationProvider : NotificationJobExecutedP
public async override Task NotifySuccessAsync([NotNull] JobActionExecuteContext context)
{
var title = StringLocalizer["JobExecutedSucceeded"].Value;
var title = StringLocalizer["Notifications:JobExecuteSucceeded"].Value;
await SendNofiterAsync(context, title, NotificationSeverity.Success);
}

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

@ -8,6 +8,8 @@
"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:NotificationName": "Notification Name",
"Description:NotificationName": "If a notification name is specified, the message will be sent using the corresponding notification name.",
"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",

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

@ -8,6 +8,8 @@
"Notifications:JobExecuteFailedDesc": "后台作业执行失败后通知推送.",
"Notifications:JobExecuteCompleted": "作业完成通知",
"Notifications:JobExecuteCompletedDesc": "后台作业执行完成后通知推送.",
"DisplayName:NotificationName": "通知名称",
"Description:NotificationName": "如果指定通知名称,将使用对应通知名称发送消息.",
"DisplayName:PushProvider": "推送程序",
"Description:PushProvider": "如果指定推送程序,应用将选择它进行消息推送,多个提供者用;分隔,可选列表:SignalR(实时通知)、Sms(短信通知)、Emailing(邮件通知)、WeChat.MiniProgram(微信小程序)、WxPusher(WxPusher微信推送服务)、PushPlus(PushPlus多平台推送服务)",
"DisplayName:Template": "模板名称",

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

@ -1,6 +1,7 @@
using JetBrains.Annotations;
using LINGYUN.Abp.BackgroundTasks.Activities;
using LINGYUN.Abp.BackgroundTasks.Localization;
using LINGYUN.Abp.BackgroundTasks.Notifications.Templates;
using LINGYUN.Abp.Notifications;
using Microsoft.Extensions.Localization;
using System;
@ -16,10 +17,13 @@ namespace LINGYUN.Abp.BackgroundTasks.Notifications;
public abstract class NotificationJobExecutedProvider : JobExecutedProvider, ITransientDependency
{
public abstract string DefaultNotificationName { get; }
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(PropertyNotificationName, L("DisplayName:NotificationName"), L("Description:NotificationName")),
new JobActionParamter(PropertyContent, L("DisplayName:Content"), L("Description:Content")),
new JobActionParamter(PropertyCulture, L("DisplayName:Culture"), L("Description:Culture")),
};
@ -33,6 +37,10 @@ public abstract class NotificationJobExecutedProvider : JobExecutedProvider, ITr
/// </summary>
public const string PropertyUseTemplate = "use-template";
/// <summary>
/// 使用自定义通知
/// </summary>
public const string PropertyNotificationName = "notification-name";
/// <summary>
/// 通知内容, 不使用模板时必须
/// </summary>
public const string PropertyContent = "content";
@ -66,7 +74,9 @@ public abstract class NotificationJobExecutedProvider : JobExecutedProvider, ITr
var useProvider = context.Action.Paramters.GetOrDefault(PropertyPushProvider)?.ToString() ?? "";
var content = context.Action.Paramters.GetOrDefault(PropertyContent)?.ToString() ?? "";
var templateName = context.Action.Paramters.GetOrDefault(PropertyUseTemplate)?.ToString()
?? BackgroundTasksNotificationNames.JobExecuteSucceeded;
?? BackgroundTasksNotificationTemplates.JobExecutedNotification;
var notificationName = context.Action.Paramters.GetOrDefault(PropertyUseTemplate)?.ToString()
?? DefaultNotificationName;
if (content.IsNullOrWhiteSpace() && !templateName.IsNullOrWhiteSpace())
{
@ -97,14 +107,14 @@ public abstract class NotificationJobExecutedProvider : JobExecutedProvider, ITr
formUser: "BackgroundTasks Engine");
await NotificationSender.SendNofiterAsync(
BackgroundTasksNotificationNames.JobExecuteSucceeded,
notificationName,
notificationData,
tenantId: CurrentTenant.Id,
severity: severity,
useProviders: useProvider.Split(';'));
}
protected string GetTitleColor(NotificationSeverity severity = NotificationSeverity.Info)
private static string GetTitleColor(NotificationSeverity severity = NotificationSeverity.Info)
{
return severity switch
{

Loading…
Cancel
Save