Browse Source

econstruct the distributed job module

1、使作业调度完成时调度用户定义Action,移除污染作业参数的异常处理参数;

2、重构用户定义作业注册方式,通过IJobDefinitionProvider注册;

3、增加IJobActionDefinitionProvider接口,用户可自行注册作业调度后处理程序;

4、增加LINGYUN.Abp.Notifications.Jobs模块,使通知相关作业独立;

5、增加LINGYUN.Abp.BackgroundTasks.DistributedLocking模块,让用户决定是否使用分布式锁定任务;

6、应用服务层增加作业Action管理接口, 便于从前端快速管理作业Action;

7、应用服务层增加作业定义查询接口, 便于从前端快速绑定作业名称、参数等.
pull/620/head
cKey 4 years ago
parent
commit
ffaf15512b
  1. 23
      aspnet-core/LINGYUN.MicroService.TaskManagement.sln
  2. 3
      aspnet-core/modules/common/LINGYUN.Abp.Notifications.Jobs/FodyWeavers.xml
  3. 30
      aspnet-core/modules/common/LINGYUN.Abp.Notifications.Jobs/FodyWeavers.xsd
  4. 24
      aspnet-core/modules/common/LINGYUN.Abp.Notifications.Jobs/LINGYUN.Abp.Notifications.Jobs.csproj
  5. 27
      aspnet-core/modules/common/LINGYUN.Abp.Notifications.Jobs/LINGYUN/Abp/Notifications/Jobs/AbpNotificationsJobsModule.cs
  6. 12
      aspnet-core/modules/common/LINGYUN.Abp.Notifications.Jobs/LINGYUN/Abp/Notifications/Jobs/LocalizableStatic.cs
  7. 7
      aspnet-core/modules/common/LINGYUN.Abp.Notifications.Jobs/LINGYUN/Abp/Notifications/Jobs/Localization/Resources/en.json
  8. 7
      aspnet-core/modules/common/LINGYUN.Abp.Notifications.Jobs/LINGYUN/Abp/Notifications/Jobs/Localization/Resources/zh-Hans.json
  9. 15
      aspnet-core/modules/common/LINGYUN.Abp.Notifications.Jobs/LINGYUN/Abp/Notifications/Jobs/NotificationCleanupJob.cs
  10. 16
      aspnet-core/modules/common/LINGYUN.Abp.Notifications.Jobs/LINGYUN/Abp/Notifications/Jobs/NotificationJobDefinitionProvider.cs
  11. 2
      aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks.Abstractions/LINGYUN.Abp.BackgroundTasks.Abstractions.csproj
  12. 6
      aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks.Abstractions/LINGYUN/Abp/BackgroundTasks/AbpBackgroundTaskConcurrentException.cs
  13. 38
      aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks.Abstractions/LINGYUN/Abp/BackgroundTasks/AbpBackgroundTasksAbstractionsModule.cs
  14. 21
      aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks.Abstractions/LINGYUN/Abp/BackgroundTasks/AbpBackgroundTasksOptions.cs
  15. 8
      aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks.Abstractions/LINGYUN/Abp/BackgroundTasks/DisableJobActionAttribute.cs
  16. 9
      aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks.Abstractions/LINGYUN/Abp/BackgroundTasks/IJobCompletedNotifierProvider.cs
  17. 12
      aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks.Abstractions/LINGYUN/Abp/BackgroundTasks/IJobDefinitionContext.cs
  18. 14
      aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks.Abstractions/LINGYUN/Abp/BackgroundTasks/IJobDefinitionManager.cs
  19. 6
      aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks.Abstractions/LINGYUN/Abp/BackgroundTasks/IJobDefinitionProvider.cs
  20. 11
      aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks.Abstractions/LINGYUN/Abp/BackgroundTasks/IJobExecutedNotifier.cs
  21. 9
      aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks.Abstractions/LINGYUN/Abp/BackgroundTasks/IJobFailedNotifierProvider.cs
  22. 9
      aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks.Abstractions/LINGYUN/Abp/BackgroundTasks/IJobSuccessNotifierProvider.cs
  23. 7
      aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks.Abstractions/LINGYUN/Abp/BackgroundTasks/JobActionType.cs
  24. 43
      aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks.Abstractions/LINGYUN/Abp/BackgroundTasks/JobDefinition.cs
  25. 38
      aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks.Abstractions/LINGYUN/Abp/BackgroundTasks/JobDefinitionContext.cs
  26. 73
      aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks.Abstractions/LINGYUN/Abp/BackgroundTasks/JobDefinitionManager.cs
  27. 27
      aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks.Abstractions/LINGYUN/Abp/BackgroundTasks/JobDefinitionParamter.cs
  28. 8
      aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks.Abstractions/LINGYUN/Abp/BackgroundTasks/JobDefinitionProvider.cs
  29. 67
      aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks.Abstractions/LINGYUN/Abp/BackgroundTasks/JobExecutedNotifier.cs
  30. 0
      aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks.Abstractions/LINGYUN/Abp/BackgroundTasks/Localization/BackgroundTasksResource.cs
  31. 19
      aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks.Abstractions/README.md
  32. 3
      aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks.Activities/FodyWeavers.xml
  33. 30
      aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks.Activities/FodyWeavers.xsd
  34. 27
      aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks.Activities/LINGYUN.Abp.BackgroundTasks.Activities.csproj
  35. 57
      aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks.Activities/LINGYUN/Abp/BackgroundTasks/Activities/AbpBackgroundTasksActivitiesModule.cs
  36. 13
      aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks.Activities/LINGYUN/Abp/BackgroundTasks/Activities/AbpBackgroundTasksActivitiesOptions.cs
  37. 15
      aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks.Activities/LINGYUN/Abp/BackgroundTasks/Activities/DefaultJobActionStore.cs
  38. 12
      aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks.Activities/LINGYUN/Abp/BackgroundTasks/Activities/IJobActionDefinitionContext.cs
  39. 14
      aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks.Activities/LINGYUN/Abp/BackgroundTasks/Activities/IJobActionDefinitionManager.cs
  40. 6
      aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks.Activities/LINGYUN/Abp/BackgroundTasks/Activities/IJobActionDefinitionProvider.cs
  41. 10
      aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks.Activities/LINGYUN/Abp/BackgroundTasks/Activities/IJobActionStore.cs
  42. 11
      aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks.Activities/LINGYUN/Abp/BackgroundTasks/Activities/IJobExecutedProvider.cs
  43. 9
      aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks.Activities/LINGYUN/Abp/BackgroundTasks/Activities/JobAction.cs
  44. 57
      aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks.Activities/LINGYUN/Abp/BackgroundTasks/Activities/JobActionDefinition.cs
  45. 37
      aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks.Activities/LINGYUN/Abp/BackgroundTasks/Activities/JobActionDefinitionContext.cs
  46. 73
      aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks.Activities/LINGYUN/Abp/BackgroundTasks/Activities/JobActionDefinitionManager.cs
  47. 8
      aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks.Activities/LINGYUN/Abp/BackgroundTasks/Activities/JobActionDefinitionProvider.cs
  48. 89
      aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks.Activities/LINGYUN/Abp/BackgroundTasks/Activities/JobActionEvent.cs
  49. 16
      aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks.Activities/LINGYUN/Abp/BackgroundTasks/Activities/JobActionExecuteContext.cs
  50. 24
      aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks.Activities/LINGYUN/Abp/BackgroundTasks/Activities/JobActionParamter.cs
  51. 22
      aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks.Activities/LINGYUN/Abp/BackgroundTasks/Activities/JobExecutedProvider.cs
  52. 5
      aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks.Activities/LINGYUN/Abp/BackgroundTasks/Activities/Localization/Resources/en.json
  53. 5
      aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks.Activities/LINGYUN/Abp/BackgroundTasks/Activities/Localization/Resources/zh-Hans.json
  54. 21
      aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks.Activities/README.md
  55. 3
      aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks.DistributedLocking/FodyWeavers.xml
  56. 30
      aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks.DistributedLocking/FodyWeavers.xsd
  57. 19
      aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks.DistributedLocking/LINGYUN.Abp.BackgroundTasks.DistributedLocking.csproj
  58. 11
      aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks.DistributedLocking/LINGYUN/Abp/BackgroundTasks/DistributedLocking/AbpBackgroundTasksDistributedLockingModule.cs
  59. 8
      aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks.DistributedLocking/LINGYUN/Abp/BackgroundTasks/DistributedLocking/JobDistributedLockingProvider.cs
  60. 17
      aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks.DistributedLocking/README.md
  61. 15
      aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks.EventBus/README.md
  62. 2
      aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks.ExceptionHandling/LINGYUN.Abp.BackgroundTasks.ExceptionHandling.csproj
  63. 7
      aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks.ExceptionHandling/LINGYUN/Abp/BackgroundTasks/ExceptionHandling/AbpBackgroundTasksExceptionHandlingModule.cs
  64. 25
      aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks.ExceptionHandling/LINGYUN/Abp/BackgroundTasks/ExceptionHandling/ExceptionHandlingJobActionDefinitionProvider.cs
  65. 144
      aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks.ExceptionHandling/LINGYUN/Abp/BackgroundTasks/ExceptionHandling/JobExecutedFailedProvider.cs
  66. 132
      aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks.ExceptionHandling/LINGYUN/Abp/BackgroundTasks/ExceptionHandling/JobFailedNotifierProvider.cs
  67. 4
      aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks.ExceptionHandling/README.md
  68. 8
      aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks.Jobs/LINGYUN.Abp.BackgroundTasks.Jobs.csproj
  69. 22
      aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks.Jobs/LINGYUN/Abp/BackgroundTasks/Jobs/AbpBackgroundTasksJobsModule.cs
  70. 11
      aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks.Jobs/LINGYUN/Abp/BackgroundTasks/Jobs/ConsoleJob.cs
  71. 51
      aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks.Jobs/LINGYUN/Abp/BackgroundTasks/Jobs/DefaultJobDefinitionProvider.cs
  72. 24
      aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks.Jobs/LINGYUN/Abp/BackgroundTasks/Jobs/HttpRequestJob.cs
  73. 12
      aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks.Jobs/LINGYUN/Abp/BackgroundTasks/Jobs/LocalizableStatic.cs
  74. 37
      aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks.Jobs/LINGYUN/Abp/BackgroundTasks/Jobs/Localization/Resources/en.json
  75. 37
      aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks.Jobs/LINGYUN/Abp/BackgroundTasks/Jobs/Localization/Resources/zh-Hans.json
  76. 19
      aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks.Jobs/LINGYUN/Abp/BackgroundTasks/Jobs/SendEmailJob.cs
  77. 13
      aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks.Jobs/LINGYUN/Abp/BackgroundTasks/Jobs/SendSmsJob.cs
  78. 17
      aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks.Jobs/LINGYUN/Abp/BackgroundTasks/Jobs/ServiceInvocationJob.cs
  79. 15
      aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks.Jobs/LINGYUN/Abp/BackgroundTasks/Jobs/SleepJob.cs
  80. 24
      aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks.Jobs/README.md
  81. 2
      aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks.Quartz/LINGYUN/Abp/BackgroundTasks/Quartz/IQuartzJobCreator.cs
  82. 36
      aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks.Quartz/LINGYUN/Abp/BackgroundTasks/Quartz/QuartzJobCreator.cs
  83. 10
      aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks.Quartz/LINGYUN/Abp/BackgroundTasks/Quartz/QuartzJobListener.cs
  84. 14
      aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks.Quartz/LINGYUN/Abp/BackgroundTasks/Quartz/QuartzJobScheduler.cs
  85. 40
      aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks.Quartz/LINGYUN/Abp/BackgroundTasks/Quartz/QuartzJobSearchJobAdapter.cs
  86. 19
      aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks.Quartz/LINGYUN/Abp/BackgroundTasks/Quartz/QuartzTriggerListener.cs
  87. 9
      aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks/LINGYUN.Abp.BackgroundTasks.csproj
  88. 6
      aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks/LINGYUN/Abp/BackgroundTasks/AbpBackgroundTasksModule.cs
  89. 2
      aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks/LINGYUN/Abp/BackgroundTasks/BackgroundWorkerAdapter.cs
  90. 0
      aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks/LINGYUN/Abp/BackgroundTasks/DefaultJobLockProvider.cs
  91. 0
      aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks/LINGYUN/Abp/BackgroundTasks/IJobLockProvider.cs
  92. 1
      aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks/LINGYUN/Abp/BackgroundTasks/Internal/BackgroundCleaningJob.cs
  93. 1
      aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks/LINGYUN/Abp/BackgroundTasks/Internal/BackgroundPollingJob.cs
  94. 32
      aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks/LINGYUN/Abp/BackgroundTasks/Internal/JobNotifierEvent.cs
  95. 2
      aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks/LINGYUN/Abp/BackgroundTasks/JobRunnableExecuter.cs
  96. 14
      aspnet-core/modules/task-management/LINGYUN.Abp.TaskManagement.Application.Contracts/LINGYUN/Abp/TaskManagement/BackgroundJobActionCreateDto.cs
  97. 20
      aspnet-core/modules/task-management/LINGYUN.Abp.TaskManagement.Application.Contracts/LINGYUN/Abp/TaskManagement/BackgroundJobActionCreateOrUpdateDto.cs
  98. 28
      aspnet-core/modules/task-management/LINGYUN.Abp.TaskManagement.Application.Contracts/LINGYUN/Abp/TaskManagement/BackgroundJobActionDefinitionDto.cs
  99. 25
      aspnet-core/modules/task-management/LINGYUN.Abp.TaskManagement.Application.Contracts/LINGYUN/Abp/TaskManagement/BackgroundJobActionDto.cs
  100. 8
      aspnet-core/modules/task-management/LINGYUN.Abp.TaskManagement.Application.Contracts/LINGYUN/Abp/TaskManagement/BackgroundJobActionGetDefinitionsInput.cs

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

@ -46,6 +46,14 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LINGYUN.Abp.BackgroundTasks
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LINGYUN.Abp.BackgroundTasks.EventBus", "modules\task-management\LINGYUN.Abp.BackgroundTasks.EventBus\LINGYUN.Abp.BackgroundTasks.EventBus.csproj", "{D17DEF79-635B-478D-89D7-32EAE616869A}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LINGYUN.Abp.BackgroundTasks.DistributedLocking", "modules\task-management\LINGYUN.Abp.BackgroundTasks.DistributedLocking\LINGYUN.Abp.BackgroundTasks.DistributedLocking.csproj", "{A817B7B7-A225-404A-A301-B42D400DE4B7}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LINGYUN.Abp.BackgroundTasks.Activities", "modules\task-management\LINGYUN.Abp.BackgroundTasks.Activities\LINGYUN.Abp.BackgroundTasks.Activities.csproj", "{3D0A1901-36FB-4DA2-9F8D-05308598E98C}"
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}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@ -112,6 +120,18 @@ Global
{D17DEF79-635B-478D-89D7-32EAE616869A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D17DEF79-635B-478D-89D7-32EAE616869A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D17DEF79-635B-478D-89D7-32EAE616869A}.Release|Any CPU.Build.0 = Release|Any CPU
{A817B7B7-A225-404A-A301-B42D400DE4B7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{A817B7B7-A225-404A-A301-B42D400DE4B7}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A817B7B7-A225-404A-A301-B42D400DE4B7}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A817B7B7-A225-404A-A301-B42D400DE4B7}.Release|Any CPU.Build.0 = Release|Any CPU
{3D0A1901-36FB-4DA2-9F8D-05308598E98C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{3D0A1901-36FB-4DA2-9F8D-05308598E98C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{3D0A1901-36FB-4DA2-9F8D-05308598E98C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{3D0A1901-36FB-4DA2-9F8D-05308598E98C}.Release|Any CPU.Build.0 = Release|Any CPU
{17D7ED0F-E789-4637-9B06-57DF693C6E1E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{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
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
@ -132,6 +152,9 @@ Global
{56C759D1-6FE6-4111-A2DB-CD65DCE82061} = {C38EB7EF-BAE9-4129-862A-71C652B81775}
{7937785C-0D28-46B3-A7E7-0B592821A1F2} = {385578CC-C0F1-4377-A7A2-682B8F416234}
{D17DEF79-635B-478D-89D7-32EAE616869A} = {C38EB7EF-BAE9-4129-862A-71C652B81775}
{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}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {E1FD1F4C-D344-408B-97CF-B6F1F6D7D293}

3
aspnet-core/modules/common/LINGYUN.Abp.Notifications.Jobs/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/common/LINGYUN.Abp.Notifications.Jobs/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>

24
aspnet-core/modules/common/LINGYUN.Abp.Notifications.Jobs/LINGYUN.Abp.Notifications.Jobs.csproj

@ -0,0 +1,24 @@
<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\Notifications\Jobs\Localization\Resources\*.json" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="LINGYUN\Abp\Notifications\Jobs\Localization\Resources\*.json" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\task-management\LINGYUN.Abp.BackgroundTasks.Abstractions\LINGYUN.Abp.BackgroundTasks.Abstractions.csproj" />
<ProjectReference Include="..\LINGYUN.Abp.Notifications\LINGYUN.Abp.Notifications.csproj" />
</ItemGroup>
</Project>

27
aspnet-core/modules/common/LINGYUN.Abp.Notifications.Jobs/LINGYUN/Abp/Notifications/Jobs/AbpNotificationsJobsModule.cs

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

12
aspnet-core/modules/common/LINGYUN.Abp.Notifications.Jobs/LINGYUN/Abp/Notifications/Jobs/LocalizableStatic.cs

@ -0,0 +1,12 @@
using LINGYUN.Abp.Notifications.Localization;
using Volo.Abp.Localization;
namespace LINGYUN.Abp.Notifications.Jobs;
internal static class LocalizableStatic
{
public static ILocalizableString Create(string name)
{
return LocalizableString.Create<NotificationsResource>(name);
}
}

7
aspnet-core/modules/common/LINGYUN.Abp.Notifications.Jobs/LINGYUN/Abp/Notifications/Jobs/Localization/Resources/en.json

@ -0,0 +1,7 @@
{
"culture": "en",
"texts": {
"NotificationCleanupJob": "Notification Cleanup Job",
"Notification:BatchCount": "Batch Count"
}
}

7
aspnet-core/modules/common/LINGYUN.Abp.Notifications.Jobs/LINGYUN/Abp/Notifications/Jobs/Localization/Resources/zh-Hans.json

@ -0,0 +1,7 @@
{
"culture": "zh-Hans",
"texts": {
"NotificationCleanupJob": "清理过期通知作业",
"Notification:BatchCount": "批次数量"
}
}

15
aspnet-core/services/LY.MicroService.RealtimeMessage.HttpApi.Host/BackgroundJobs/NotificationCleanupJob.cs → aspnet-core/modules/common/LINGYUN.Abp.Notifications.Jobs/LINGYUN/Abp/Notifications/Jobs/NotificationCleanupJob.cs

@ -1,17 +1,26 @@
using LINGYUN.Abp.BackgroundTasks;
using LINGYUN.Abp.Notifications;
using System.Collections.Generic;
using System.Threading.Tasks;
namespace LY.MicroService.RealtimeMessage.BackgroundJobs;
namespace LINGYUN.Abp.Notifications.Jobs;
public class NotificationCleanupJob : IJobRunnable
{
#region Definition Paramters
public readonly static IReadOnlyList<JobDefinitionParamter> Paramters =
new List<JobDefinitionParamter>
{
new JobDefinitionParamter(PropertyBatchCount, LocalizableStatic.Create("Notification:BatchCount"))
};
#endregion
public const string Name = "NotificationCleanupJob";
/// <summary>
/// 每次清除记录大小
/// </summary>
public const string PropertyBatchCount = "BatchCount";
public async virtual Task ExecuteAsync(JobRunnableContext context)
{
var count = context.GetJobData<int>(PropertyBatchCount);

16
aspnet-core/modules/common/LINGYUN.Abp.Notifications.Jobs/LINGYUN/Abp/Notifications/Jobs/NotificationJobDefinitionProvider.cs

@ -0,0 +1,16 @@
using LINGYUN.Abp.BackgroundTasks;
namespace LINGYUN.Abp.Notifications.Jobs;
public class NotificationJobDefinitionProvider : JobDefinitionProvider
{
public override void Define(IJobDefinitionContext context)
{
context.Add(
new JobDefinition(
NotificationCleanupJob.Name,
typeof(NotificationCleanupJob),
LocalizableStatic.Create("NotificationCleanupJob"),
NotificationCleanupJob.Paramters));
}
}

2
aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks.Abstractions/LINGYUN.Abp.BackgroundTasks.Abstractions.csproj

@ -9,7 +9,7 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Volo.Abp.Core" Version="$(VoloAbpPackageVersion)" />
<PackageReference Include="Volo.Abp.Localization" Version="$(VoloAbpPackageVersion)" />
</ItemGroup>
</Project>

6
aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks.Abstractions/LINGYUN/Abp/BackgroundTasks/AbpBackgroundTaskConcurrentException.cs

@ -5,7 +5,7 @@ namespace LINGYUN.Abp.BackgroundTasks;
public class AbpBackgroundTaskConcurrentException : AbpJobExecutionException
{
/// <summary>
/// Creates a new <see cref="AbpBackgroundTaskConcurrentException"/> object.
/// Creates a new <see cref="Task"/> object.
/// </summary>
/// <param name="innerException">Inner exception</param>
public AbpBackgroundTaskConcurrentException(Type jobType)
@ -17,7 +17,7 @@ public class AbpBackgroundTaskConcurrentException : AbpJobExecutionException
}
/// <summary>
/// Creates a new <see cref="AbpBackgroundTaskConcurrentException"/> object.
/// Creates a new <see cref="Task"/> object.
/// </summary>
/// <param name="jobType">Execute job type</param>
/// <param name="innerException">Inner exception</param>
@ -30,7 +30,7 @@ public class AbpBackgroundTaskConcurrentException : AbpJobExecutionException
}
/// <summary>
/// Creates a new <see cref="AbpBackgroundTaskConcurrentException"/> object.
/// Creates a new <see cref="Task"/> object.
/// </summary>
/// <param name="jobType">Execute job type</param>
/// <param name="message">Exception message</param>

38
aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks.Abstractions/LINGYUN/Abp/BackgroundTasks/AbpBackgroundTasksAbstractionsModule.cs

@ -1,7 +1,43 @@
using Volo.Abp.Modularity;
using LINGYUN.Abp.BackgroundTasks.Localization;
using Microsoft.Extensions.DependencyInjection;
using System;
using System.Collections.Generic;
using Volo.Abp.Localization;
using Volo.Abp.Modularity;
namespace LINGYUN.Abp.BackgroundTasks;
[DependsOn(typeof(AbpLocalizationModule))]
public class AbpBackgroundTasksAbstractionsModule : AbpModule
{
public override void PreConfigureServices(ServiceConfigurationContext context)
{
AutoAddDefinitionProviders(context.Services);
}
public override void ConfigureServices(ServiceConfigurationContext context)
{
Configure<AbpLocalizationOptions>(options =>
{
options.Resources.Add<BackgroundTasksResource>("en");
});
}
private static void AutoAddDefinitionProviders(IServiceCollection services)
{
var definitionProviders = new List<Type>();
services.OnRegistred(context =>
{
if (typeof(IJobDefinitionProvider).IsAssignableFrom(context.ImplementationType))
{
definitionProviders.Add(context.ImplementationType);
}
});
services.Configure<AbpBackgroundTasksOptions>(options =>
{
options.DefinitionProviders.AddIfNotContains(definitionProviders);
});
}
}

21
aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks.Abstractions/LINGYUN/Abp/BackgroundTasks/AbpBackgroundTasksOptions.cs

@ -1,5 +1,4 @@
using System;
using System.Collections.Generic;
using Volo.Abp.Collections;
namespace LINGYUN.Abp.BackgroundTasks;
@ -19,10 +18,13 @@ public class AbpBackgroundTasksOptions
/// <remarks>
/// 用户实现的作业可以添加在集合中
/// </remarks>
public IDictionary<string, Type> JobProviders { get; }
public ITypeList<IJobDefinitionProvider> DefinitionProviders { get; }
/// <summary>
/// 启用清理任务
/// </summary>
/// <remarks>
/// 主节点启用
/// </remarks>
public bool JobCleanEnabled { get; set; }
/// <summary>
/// 任务过期时间
@ -48,6 +50,9 @@ public class AbpBackgroundTasksOptions
/// <summary>
/// 启用轮询任务
/// </summary>
/// <remarks>
/// 主节点启用
/// </remarks>
public bool JobFetchEnabled { get; set; }
/// <summary>
/// 每次轮询任务批次大小
@ -76,23 +81,17 @@ public class AbpBackgroundTasksOptions
public string NodeName { get; set; }
public AbpBackgroundTasksOptions()
{
JobFetchEnabled = true;
JobFetchEnabled = false;
MaxJobFetchCount = 1000;
JobFetchLockTimeOut = 120;
JobFetchCronExpression = "0/30 * * * * ? ";
JobCleanEnabled = true;
JobCleanEnabled = false;
MaxJobCleanCount = 1000;
JobExpiratime = TimeSpan.FromDays(15d);
JobCleanCronExpression = "0 0/10 * * * ? *";
JobMonitors = new TypeList<IJobEvent>();
JobProviders = new Dictionary<string, Type>();
}
public void AddProvider<TJobRunnable>(string name)
where TJobRunnable : IJobRunnable
{
JobProviders[name] = typeof(TJobRunnable);
DefinitionProviders = new TypeList<IJobDefinitionProvider>();
}
}

8
aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks.Abstractions/LINGYUN/Abp/BackgroundTasks/DisableJobActionAttribute.cs

@ -0,0 +1,8 @@
using System;
namespace LINGYUN.Abp.BackgroundTasks;
[AttributeUsage(AttributeTargets.Class)]
public class DisableJobActionAttribute : Attribute
{
}

9
aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks.Abstractions/LINGYUN/Abp/BackgroundTasks/IJobCompletedNotifierProvider.cs

@ -1,9 +0,0 @@
using JetBrains.Annotations;
using System.Threading.Tasks;
namespace LINGYUN.Abp.BackgroundTasks;
public interface IJobCompletedNotifierProvider
{
Task NotifyComplateAsync([NotNull] JobEventContext context);
}

12
aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks.Abstractions/LINGYUN/Abp/BackgroundTasks/IJobDefinitionContext.cs

@ -0,0 +1,12 @@
using System.Collections.Generic;
namespace LINGYUN.Abp.BackgroundTasks;
public interface IJobDefinitionContext
{
JobDefinition GetOrNull(string name);
IReadOnlyList<JobDefinition> GetAll();
void Add(params JobDefinition[] definitions);
}

14
aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks.Abstractions/LINGYUN/Abp/BackgroundTasks/IJobDefinitionManager.cs

@ -0,0 +1,14 @@
using JetBrains.Annotations;
using System.Collections.Generic;
namespace LINGYUN.Abp.BackgroundTasks;
public interface IJobDefinitionManager
{
[NotNull]
JobDefinition Get([NotNull] string name);
IReadOnlyList<JobDefinition> GetAll();
JobDefinition GetOrNull(string name);
}

6
aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks.Abstractions/LINGYUN/Abp/BackgroundTasks/IJobDefinitionProvider.cs

@ -0,0 +1,6 @@
namespace LINGYUN.Abp.BackgroundTasks;
public interface IJobDefinitionProvider
{
void Define(IJobDefinitionContext context);
}

11
aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks.Abstractions/LINGYUN/Abp/BackgroundTasks/IJobExecutedNotifier.cs

@ -1,11 +0,0 @@
using JetBrains.Annotations;
using System.Threading.Tasks;
namespace LINGYUN.Abp.BackgroundTasks;
public interface IJobExecutedNotifier
{
Task NotifyErrorAsync([NotNull] JobEventContext context);
Task NotifySuccessAsync([NotNull] JobEventContext context);
Task NotifyComplateAsync([NotNull] JobEventContext context);
}

9
aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks.Abstractions/LINGYUN/Abp/BackgroundTasks/IJobFailedNotifierProvider.cs

@ -1,9 +0,0 @@
using JetBrains.Annotations;
using System.Threading.Tasks;
namespace LINGYUN.Abp.BackgroundTasks;
public interface IJobFailedNotifierProvider
{
Task NotifyErrorAsync([NotNull] JobEventContext context);
}

9
aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks.Abstractions/LINGYUN/Abp/BackgroundTasks/IJobSuccessNotifierProvider.cs

@ -1,9 +0,0 @@
using JetBrains.Annotations;
using System.Threading.Tasks;
namespace LINGYUN.Abp.BackgroundTasks;
public interface IJobSuccessNotifierProvider
{
Task NotifySuccessAsync([NotNull] JobEventContext context);
}

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

@ -0,0 +1,7 @@
namespace LINGYUN.Abp.BackgroundTasks;
public enum JobActionType
{
Failed = -1,
Successed = 0,
}

43
aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks.Abstractions/LINGYUN/Abp/BackgroundTasks/JobDefinition.cs

@ -0,0 +1,43 @@
using JetBrains.Annotations;
using System;
using System.Collections.Generic;
using Volo.Abp.Localization;
namespace LINGYUN.Abp.BackgroundTasks;
public class JobDefinition
{
/// <summary>
/// 名称
/// </summary>
public string Name { get; }
/// <summary>
/// 作业类型
/// </summary>
public Type JobType { get; }
/// <summary>
/// 显示名称
/// </summary>
public ILocalizableString DisplayName { get; }
/// <summary>
/// 描述
/// </summary>
public ILocalizableString Description { get; }
/// <summary>
/// 参数列表
/// </summary>
public IReadOnlyList<JobDefinitionParamter> Paramters { get; }
public JobDefinition(
[NotNull] string name,
[NotNull] Type jobType,
[NotNull] ILocalizableString displayName,
[CanBeNull] IReadOnlyList<JobDefinitionParamter> paramters = null,
[CanBeNull] ILocalizableString description = null)
{
Name = name;
JobType = jobType;
DisplayName = displayName;
Description = description;
Paramters = paramters ?? new JobDefinitionParamter[0];
}
}

38
aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks.Abstractions/LINGYUN/Abp/BackgroundTasks/JobDefinitionContext.cs

@ -0,0 +1,38 @@
using System;
using System.Collections.Generic;
using System.Collections.Immutable;
namespace LINGYUN.Abp.BackgroundTasks;
public class JobDefinitionContext : IJobDefinitionContext
{
protected Dictionary<string, JobDefinition> Jobs { get; }
public JobDefinitionContext(Dictionary<string, JobDefinition> jobs)
{
Jobs = jobs;
}
public virtual JobDefinition GetOrNull(string name)
{
return Jobs.GetOrDefault(name);
}
public virtual IReadOnlyList<JobDefinition> GetAll()
{
return Jobs.Values.ToImmutableList();
}
public virtual void Add(params JobDefinition[] definitions)
{
if (definitions.IsNullOrEmpty())
{
return;
}
foreach (var definition in definitions)
{
Jobs[definition.Name] = definition;
}
}
}

73
aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks.Abstractions/LINGYUN/Abp/BackgroundTasks/JobDefinitionManager.cs

@ -0,0 +1,73 @@
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Options;
using System;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Linq;
using Volo.Abp;
using Volo.Abp.DependencyInjection;
namespace LINGYUN.Abp.BackgroundTasks;
public class JobDefinitionManager : IJobDefinitionManager, ISingletonDependency
{
protected Lazy<IDictionary<string, JobDefinition>> JobDefinitions { get; }
protected AbpBackgroundTasksOptions Options { get; }
protected IServiceProvider ServiceProvider { get; }
public JobDefinitionManager(
IOptions<AbpBackgroundTasksOptions> options,
IServiceProvider serviceProvider)
{
ServiceProvider = serviceProvider;
Options = options.Value;
JobDefinitions = new Lazy<IDictionary<string, JobDefinition>>(CreateJobDefinitions, true);
}
public virtual JobDefinition Get(string name)
{
Check.NotNull(name, nameof(name));
var action = GetOrNull(name);
if (action == null)
{
throw new AbpException("Undefined job: " + name);
}
return action;
}
public virtual IReadOnlyList<JobDefinition> GetAll()
{
return JobDefinitions.Value.Values.ToImmutableList();
}
public virtual JobDefinition GetOrNull(string name)
{
return JobDefinitions.Value.GetOrDefault(name);
}
protected virtual IDictionary<string, JobDefinition> CreateJobDefinitions()
{
var jobs = new Dictionary<string, JobDefinition>();
using (var scope = ServiceProvider.CreateScope())
{
var providers = Options
.DefinitionProviders
.Select(p => scope.ServiceProvider.GetRequiredService(p) as IJobDefinitionProvider)
.ToList();
foreach (var provider in providers)
{
provider.Define(new JobDefinitionContext(jobs));
}
}
return jobs;
}
}

27
aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks.Abstractions/LINGYUN/Abp/BackgroundTasks/JobDefinitionParamter.cs

@ -0,0 +1,27 @@
using JetBrains.Annotations;
using Volo.Abp.Localization;
namespace LINGYUN.Abp.BackgroundTasks;
public class JobDefinitionParamter
{
public string Name { get; }
public bool Required { get; }
public ILocalizableString DisplayName { get; }
public ILocalizableString Description { get; }
public JobDefinitionParamter(
[NotNull] string name,
[NotNull] ILocalizableString displayName,
[CanBeNull] ILocalizableString description = null,
bool required = false)
{
Name = name;
Required = required;
DisplayName = displayName;
Description = description;
}
}

8
aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks.Abstractions/LINGYUN/Abp/BackgroundTasks/JobDefinitionProvider.cs

@ -0,0 +1,8 @@
using Volo.Abp.DependencyInjection;
namespace LINGYUN.Abp.BackgroundTasks;
public abstract class JobDefinitionProvider : IJobDefinitionProvider, ITransientDependency
{
public abstract void Define(IJobDefinitionContext context);
}

67
aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks.Abstractions/LINGYUN/Abp/BackgroundTasks/JobExecutedNotifier.cs

@ -1,67 +0,0 @@
using JetBrains.Annotations;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging.Abstractions;
using System;
using System.Threading.Tasks;
using Volo.Abp.DependencyInjection;
namespace LINGYUN.Abp.BackgroundTasks;
public class JobExecutedNotifier : IJobExecutedNotifier, ISingletonDependency
{
public ILogger<JobExecutedNotifier> Logger { protected get; set; }
public JobExecutedNotifier()
{
Logger = NullLogger<JobExecutedNotifier>.Instance;
}
public async Task NotifyComplateAsync([NotNull] JobEventContext context)
{
var notifier = context.ServiceProvider.GetService<IJobCompletedNotifierProvider>();
if (notifier != null)
{
try
{
await notifier.NotifyComplateAsync(context);
}
catch (Exception ex)
{
Logger.LogWarning($"An exception thow with job complete notify: {ex.Message}");
}
}
}
public async Task NotifyErrorAsync([NotNull] JobEventContext context)
{
var notifier = context.ServiceProvider.GetService<IJobFailedNotifierProvider>();
if (notifier != null)
{
try
{
await notifier.NotifyErrorAsync(context);
}
catch (Exception ex)
{
Logger.LogWarning($"An exception thow with job error notify: {ex.Message}");
}
}
}
public async Task NotifySuccessAsync([NotNull] JobEventContext context)
{
var notifier = context.ServiceProvider.GetService<IJobSuccessNotifierProvider>();
if (notifier != null)
{
try
{
await notifier.NotifySuccessAsync(context);
}
catch (Exception ex)
{
Logger.LogWarning($"An exception thow with job success notify: {ex.Message}");
}
}
}
}

0
aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks/LINGYUN/Abp/BackgroundTasks/Localization/BackgroundTasksResource.cs → aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks.Abstractions/LINGYUN/Abp/BackgroundTasks/Localization/BackgroundTasksResource.cs

19
aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks.Abstractions/README.md

@ -0,0 +1,19 @@
# LINGYUN.Abp.BackgroundTasks.Abstractions
后台任务(队列)模块抽象层,定义一些基本构造与接口
## 特性参数
* DisableJobActionAttribute 标记此特性不处理作业触发后行为
## 配置使用
模块按需引用
```csharp
[DependsOn(typeof(AbpBackgroundTasksAbstractionsModule))]
public class YouProjectModule : AbpModule
{
// other
}
```

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

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

30
aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks.Activities/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>

27
aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks.Activities/LINGYUN.Abp.BackgroundTasks.Activities.csproj

@ -0,0 +1,27 @@
<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\Activities\Localization\Resources\*.json" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="LINGYUN\Abp\BackgroundTasks\Activities\Localization\Resources\*.json" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Volo.Abp.Localization" Version="$(VoloAbpPackageVersion)" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\LINGYUN.Abp.BackgroundTasks.Abstractions\LINGYUN.Abp.BackgroundTasks.Abstractions.csproj" />
</ItemGroup>
</Project>

57
aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks.Activities/LINGYUN/Abp/BackgroundTasks/Activities/AbpBackgroundTasksActivitiesModule.cs

@ -0,0 +1,57 @@
using LINGYUN.Abp.BackgroundTasks.Localization;
using Microsoft.Extensions.DependencyInjection;
using System;
using System.Collections.Generic;
using Volo.Abp.Localization;
using Volo.Abp.Modularity;
using Volo.Abp.VirtualFileSystem;
namespace LINGYUN.Abp.BackgroundTasks.Activities;
[DependsOn(typeof(AbpLocalizationModule))]
[DependsOn(typeof(AbpBackgroundTasksAbstractionsModule))]
public class AbpBackgroundTasksActivitiesModule : AbpModule
{
public override void PreConfigureServices(ServiceConfigurationContext context)
{
AutoAddDefinitionProviders(context.Services);
}
public override void ConfigureServices(ServiceConfigurationContext context)
{
Configure<AbpVirtualFileSystemOptions>(options =>
{
options.FileSets.AddEmbedded<AbpBackgroundTasksActivitiesModule>();
});
Configure<AbpLocalizationOptions>(options =>
{
options.Resources
.Get<BackgroundTasksResource>()
.AddVirtualJson("/LINGYUN/Abp/BackgroundTasks/Activities/Localization/Resources");
});
Configure<AbpBackgroundTasksOptions>(options =>
{
options.JobMonitors.AddIfNotContains(typeof(JobActionEvent));
});
}
private static void AutoAddDefinitionProviders(IServiceCollection services)
{
var definitionProviders = new List<Type>();
services.OnRegistred(context =>
{
if (typeof(IJobActionDefinitionProvider).IsAssignableFrom(context.ImplementationType))
{
definitionProviders.Add(context.ImplementationType);
}
});
services.Configure<AbpBackgroundTasksActivitiesOptions>(options =>
{
options.DefinitionProviders.AddIfNotContains(definitionProviders);
});
}
}

13
aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks.Activities/LINGYUN/Abp/BackgroundTasks/Activities/AbpBackgroundTasksActivitiesOptions.cs

@ -0,0 +1,13 @@
using Volo.Abp.Collections;
namespace LINGYUN.Abp.BackgroundTasks.Activities;
public class AbpBackgroundTasksActivitiesOptions
{
public ITypeList<IJobActionDefinitionProvider> DefinitionProviders { get; }
public AbpBackgroundTasksActivitiesOptions()
{
DefinitionProviders = new TypeList<IJobActionDefinitionProvider>();
}
}

15
aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks.Activities/LINGYUN/Abp/BackgroundTasks/Activities/DefaultJobActionStore.cs

@ -0,0 +1,15 @@
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
using Volo.Abp.DependencyInjection;
namespace LINGYUN.Abp.BackgroundTasks.Activities;
[Dependency(TryRegister = true)]
public class DefaultJobActionStore : IJobActionStore, ISingletonDependency
{
public Task<List<JobAction>> GetActionsAsync(string id, CancellationToken cancellationToken = default)
{
return Task.FromResult(new List<JobAction>());
}
}

12
aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks.Activities/LINGYUN/Abp/BackgroundTasks/Activities/IJobActionDefinitionContext.cs

@ -0,0 +1,12 @@
using System.Collections.Generic;
namespace LINGYUN.Abp.BackgroundTasks.Activities;
public interface IJobActionDefinitionContext
{
JobActionDefinition GetOrNull(string name);
IReadOnlyList<JobActionDefinition> GetAll();
void Add(params JobActionDefinition[] definitions);
}

14
aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks.Activities/LINGYUN/Abp/BackgroundTasks/Activities/IJobActionDefinitionManager.cs

@ -0,0 +1,14 @@
using JetBrains.Annotations;
using System.Collections.Generic;
namespace LINGYUN.Abp.BackgroundTasks.Activities;
public interface IJobActionDefinitionManager
{
[NotNull]
JobActionDefinition Get([NotNull] string name);
IReadOnlyList<JobActionDefinition> GetAll();
JobActionDefinition GetOrNull(string name);
}

6
aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks.Activities/LINGYUN/Abp/BackgroundTasks/Activities/IJobActionDefinitionProvider.cs

@ -0,0 +1,6 @@
namespace LINGYUN.Abp.BackgroundTasks.Activities;
public interface IJobActionDefinitionProvider
{
void Define(IJobActionDefinitionContext context);
}

10
aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks.Activities/LINGYUN/Abp/BackgroundTasks/Activities/IJobActionStore.cs

@ -0,0 +1,10 @@
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
namespace LINGYUN.Abp.BackgroundTasks.Activities;
public interface IJobActionStore
{
Task<List<JobAction>> GetActionsAsync(string id, CancellationToken cancellationToken = default);
}

11
aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks.Activities/LINGYUN/Abp/BackgroundTasks/Activities/IJobExecutedProvider.cs

@ -0,0 +1,11 @@
using JetBrains.Annotations;
using System.Threading.Tasks;
namespace LINGYUN.Abp.BackgroundTasks.Activities;
public interface IJobExecutedProvider
{
Task NotifyErrorAsync([NotNull] JobActionExecuteContext context);
Task NotifySuccessAsync([NotNull] JobActionExecuteContext context);
Task NotifyComplateAsync([NotNull] JobActionExecuteContext context);
}

9
aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks.Activities/LINGYUN/Abp/BackgroundTasks/Activities/JobAction.cs

@ -0,0 +1,9 @@
using System.Collections.Generic;
namespace LINGYUN.Abp.BackgroundTasks.Activities;
public class JobAction
{
public string Name { get; set; }
public Dictionary<string, object> Paramters { get; set; }
}

57
aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks.Activities/LINGYUN/Abp/BackgroundTasks/Activities/JobActionDefinition.cs

@ -0,0 +1,57 @@
using JetBrains.Annotations;
using System.Collections.Generic;
using Volo.Abp.Collections;
using Volo.Abp.Localization;
namespace LINGYUN.Abp.BackgroundTasks.Activities;
public class JobActionDefinition
{
/// <summary>
/// 名称
/// </summary>
public string Name { get; }
/// <summary>
/// 类型
/// </summary>
public JobActionType Type { get; }
/// <summary>
/// 显示名称
/// </summary>
public ILocalizableString DisplayName { get; }
/// <summary>
/// 描述
/// </summary>
public ILocalizableString Description { get; }
/// <summary>
/// 参数列表
/// </summary>
public IList<JobActionParamter> Paramters { get; }
/// <summary>
/// 通知提供者
/// </summary>
public ITypeList<IJobExecutedProvider> Providers { get; }
public JobActionDefinition(
[NotNull] string name,
[NotNull] JobActionType type,
[NotNull] ILocalizableString displayName,
[NotNull] IList<JobActionParamter> paramters,
ILocalizableString description = null)
{
Name = name;
Type = type;
DisplayName = displayName;
Paramters = paramters;
Description = description;
Providers = new TypeList<IJobExecutedProvider>();
}
public virtual JobActionDefinition WithProvider<TProvider>()
where TProvider : IJobExecutedProvider
{
Providers.Add(typeof(TProvider));
return this;
}
}

37
aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks.Activities/LINGYUN/Abp/BackgroundTasks/Activities/JobActionDefinitionContext.cs

@ -0,0 +1,37 @@
using System;
using System.Collections.Generic;
using System.Collections.Immutable;
namespace LINGYUN.Abp.BackgroundTasks.Activities;
public class JobActionDefinitionContext : IJobActionDefinitionContext
{
protected Dictionary<string, JobActionDefinition> Actions { get; }
public JobActionDefinitionContext(Dictionary<string, JobActionDefinition> actions)
{
Actions = actions;
}
public virtual JobActionDefinition GetOrNull(string name)
{
return Actions.GetOrDefault(name);
}
public virtual IReadOnlyList<JobActionDefinition> GetAll()
{
return Actions.Values.ToImmutableList();
}
public virtual void Add(params JobActionDefinition[] definitions)
{
if (definitions.IsNullOrEmpty())
{
return;
}
foreach (var definition in definitions)
{
Actions[definition.Name] = definition;
}
}
}

73
aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks.Activities/LINGYUN/Abp/BackgroundTasks/Activities/JobActionDefinitionManager.cs

@ -0,0 +1,73 @@
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Options;
using System;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Linq;
using Volo.Abp;
using Volo.Abp.DependencyInjection;
namespace LINGYUN.Abp.BackgroundTasks.Activities;
public class JobActionDefinitionManager : IJobActionDefinitionManager, ISingletonDependency
{
protected Lazy<IDictionary<string, JobActionDefinition>> ActionDefinitions { get; }
protected AbpBackgroundTasksActivitiesOptions Options { get; }
protected IServiceProvider ServiceProvider { get; }
public JobActionDefinitionManager(
IOptions<AbpBackgroundTasksActivitiesOptions> options,
IServiceProvider serviceProvider)
{
ServiceProvider = serviceProvider;
Options = options.Value;
ActionDefinitions = new Lazy<IDictionary<string, JobActionDefinition>>(CreateSettingDefinitions, true);
}
public virtual JobActionDefinition Get(string name)
{
Check.NotNull(name, nameof(name));
var action = GetOrNull(name);
if (action == null)
{
throw new AbpException("Undefined action: " + name);
}
return action;
}
public virtual IReadOnlyList<JobActionDefinition> GetAll()
{
return ActionDefinitions.Value.Values.ToImmutableList();
}
public virtual JobActionDefinition GetOrNull(string name)
{
return ActionDefinitions.Value.GetOrDefault(name);
}
protected virtual IDictionary<string, JobActionDefinition> CreateSettingDefinitions()
{
var actions = new Dictionary<string, JobActionDefinition>();
using (var scope = ServiceProvider.CreateScope())
{
var providers = Options
.DefinitionProviders
.Select(p => scope.ServiceProvider.GetRequiredService(p) as IJobActionDefinitionProvider)
.ToList();
foreach (var provider in providers)
{
provider.Define(new JobActionDefinitionContext(actions));
}
}
return actions;
}
}

8
aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks.Activities/LINGYUN/Abp/BackgroundTasks/Activities/JobActionDefinitionProvider.cs

@ -0,0 +1,8 @@
using Volo.Abp.DependencyInjection;
namespace LINGYUN.Abp.BackgroundTasks.Activities;
public abstract class JobActionDefinitionProvider : IJobActionDefinitionProvider, ITransientDependency
{
public abstract void Define(IJobActionDefinitionContext context);
}

89
aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks.Activities/LINGYUN/Abp/BackgroundTasks/Activities/JobActionEvent.cs

@ -0,0 +1,89 @@
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Volo.Abp.DependencyInjection;
namespace LINGYUN.Abp.BackgroundTasks.Activities;
public class JobActionEvent : JobEventBase<JobActionEvent>, ITransientDependency
{
protected async override Task OnJobAfterExecutedAsync(JobEventContext context)
{
if (context.EventData.Type.IsDefined(typeof(DisableJobActionAttribute), true))
{
return;
}
var actions = await GetJobActions(context);
if (!actions.Any())
{
return;
}
var provider = context.ServiceProvider.GetRequiredService<IJobActionDefinitionManager>();
foreach (var action in actions)
{
var definition = provider.GetOrNull(action.Name);
if (definition == null)
{
Logger.LogWarning($"Cannot execute job action {definition.Name}, Because it's not registered.");
continue;
}
await ExecuteAction(context, definition, action);
}
}
private async Task<List<JobAction>> GetJobActions(JobEventContext context)
{
var store = context.ServiceProvider.GetRequiredService<IJobActionStore>();
return await store.GetActionsAsync(context.EventData.Key);
}
private async Task ExecuteAction(JobEventContext context, JobActionDefinition actionDefinition, JobAction action)
{
var missingRequiredParams = actionDefinition.Paramters
.Where(p => p.Required)
.Where(rp => !action.Paramters.Any(p => string.Equals(rp.Name, p.Key)))
.Select(rp => rp.Name);
if (missingRequiredParams.Any())
{
Logger.LogWarning($"Cannot execute job action {actionDefinition.Name}, The required parameters are missing: {missingRequiredParams.JoinAsString(Environment.NewLine)}");
return;
}
var notifierContext = new JobActionExecuteContext(action, context);
foreach (var notifierType in actionDefinition.Providers)
{
if (context.ServiceProvider.GetService(notifierType) is IJobExecutedProvider notifier)
{
if (context.EventData.Exception != null)
{
if (actionDefinition.Type == JobActionType.Failed)
{
await notifier.NotifyErrorAsync(notifierContext);
Logger.LogInformation($"Executed Failed action with {notifierType.Name} was Successed.");
}
continue;
}
if (actionDefinition.Type == JobActionType.Successed)
{
await notifier.NotifySuccessAsync(notifierContext);
Logger.LogInformation($"Executed Successed action with {notifierType.Name} was Successed.");
}
await notifier.NotifyComplateAsync(notifierContext);
Logger.LogInformation($"Executed Complated action with {notifierType.Name} was Successed.");
}
}
}
}

16
aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks.Activities/LINGYUN/Abp/BackgroundTasks/Activities/JobActionExecuteContext.cs

@ -0,0 +1,16 @@
using JetBrains.Annotations;
namespace LINGYUN.Abp.BackgroundTasks.Activities;
public class JobActionExecuteContext
{
public JobAction Action { get; }
public JobEventContext Event { get; }
public JobActionExecuteContext(
[NotNull] JobAction action,
[NotNull] JobEventContext @event)
{
Action = action;
Event = @event;
}
}

24
aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks.Activities/LINGYUN/Abp/BackgroundTasks/Activities/JobActionParamter.cs

@ -0,0 +1,24 @@
using JetBrains.Annotations;
using Volo.Abp.Localization;
namespace LINGYUN.Abp.BackgroundTasks.Activities;
public class JobActionParamter
{
public string Name { get; set; }
public bool Required { get; set; }
public ILocalizableString DisplayName { get; set; }
public ILocalizableString Description { get; set; }
public JobActionParamter(
[NotNull] string name,
[NotNull] ILocalizableString displayName,
[CanBeNull] ILocalizableString description = null,
bool required = false)
{
Name = name;
DisplayName = displayName;
Description = description;
Required = required;
}
}

22
aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks.Activities/LINGYUN/Abp/BackgroundTasks/Activities/JobExecutedProvider.cs

@ -0,0 +1,22 @@
using JetBrains.Annotations;
using System.Threading.Tasks;
namespace LINGYUN.Abp.BackgroundTasks.Activities;
public abstract class JobExecutedProvider : IJobExecutedProvider
{
public virtual Task NotifyComplateAsync([NotNull] JobActionExecuteContext context)
{
return Task.CompletedTask;
}
public virtual Task NotifyErrorAsync([NotNull] JobActionExecuteContext context)
{
return Task.CompletedTask;
}
public virtual Task NotifySuccessAsync([NotNull] JobActionExecuteContext context)
{
return Task.CompletedTask;
}
}

5
aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks.Activities/LINGYUN/Abp/BackgroundTasks/Activities/Localization/Resources/en.json

@ -0,0 +1,5 @@
{
"culture": "en",
"texts": {
}
}

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

@ -0,0 +1,5 @@
{
"culture": "zh-Hans",
"texts": {
}
}

21
aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks.Activities/README.md

@ -0,0 +1,21 @@
# LINGYUN.Abp.BackgroundTasks.Activities
后台任务(队列)模块行为处理模块
## 接口参数
* IJobActionStore 实现此接口获取作业管理行为
* JobActionDefinitionProvider 实现此接口自定义作业行为
* JobExecutedProvider 实现此接口扩展作业行为
## 配置使用
模块按需引用
```csharp
[DependsOn(typeof(AbpBackgroundTasksActivitiesModule))]
public class YouProjectModule : AbpModule
{
// other
}
```

3
aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks.DistributedLocking/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.DistributedLocking/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>

19
aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks.DistributedLocking/LINGYUN.Abp.BackgroundTasks.DistributedLocking.csproj

@ -0,0 +1,19 @@
<Project Sdk="Microsoft.NET.Sdk">
<Import Project="..\..\..\configureawait.props" />
<Import Project="..\..\..\common.props" />
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<RootNamespace />
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Volo.Abp.DistributedLocking.Abstractions" Version="$(VoloAbpPackageVersion)" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\LINGYUN.Abp.BackgroundTasks\LINGYUN.Abp.BackgroundTasks.csproj" />
</ItemGroup>
</Project>

11
aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks.DistributedLocking/LINGYUN/Abp/BackgroundTasks/DistributedLocking/AbpBackgroundTasksDistributedLockingModule.cs

@ -0,0 +1,11 @@
using Volo.Abp.DistributedLocking;
using Volo.Abp.Modularity;
namespace LINGYUN.Abp.BackgroundTasks.DistributedLocking;
[DependsOn(typeof(AbpBackgroundTasksModule))]
[DependsOn(typeof(AbpDistributedLockingAbstractionsModule))]
public class AbpBackgroundTasksDistributedLockingModule : AbpModule
{
}

8
aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks/LINGYUN/Abp/BackgroundTasks/JobLockProvider.cs → aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks.DistributedLocking/LINGYUN/Abp/BackgroundTasks/DistributedLocking/JobDistributedLockingProvider.cs

@ -4,15 +4,15 @@ using System.Threading.Tasks;
using Volo.Abp.DependencyInjection;
using Volo.Abp.DistributedLocking;
namespace LINGYUN.Abp.BackgroundTasks;
namespace LINGYUN.Abp.BackgroundTasks.DistributedLocking;
[Dependency(ReplaceServices = true)]
public class JobLockProvider : IJobLockProvider, ISingletonDependency
public class JobDistributedLockingProvider : IJobLockProvider, ISingletonDependency
{
protected IMemoryCache LockCache { get; }
protected IAbpDistributedLock DistributedLock { get; }
public JobLockProvider(
public JobDistributedLockingProvider(
IMemoryCache lockCache,
IAbpDistributedLock distributedLock)
{
@ -28,7 +28,7 @@ public class JobLockProvider : IJobLockProvider, ISingletonDependency
await LockCache.GetOrCreateAsync(jobKey, (entry) =>
{
entry.SetAbsoluteExpiration(TimeSpan.FromSeconds(lockSeconds));
entry.RegisterPostEvictionCallback(async (key, value, reason, state) =>
entry.RegisterPostEvictionCallback(async (object key, object value, EvictionReason reason, object state) =>
{
if (reason == EvictionReason.Expired && value is IAbpDistributedLockHandle handleValue)
{

17
aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks.DistributedLocking/README.md

@ -0,0 +1,17 @@
# LINGYUN.Abp.BackgroundTasks.DistributedLocking
后台任务(队列)模块分布式锁模块
See: [Distributed-Locking](https://docs.abp.io/en/abp/latest/Distributed-Locking)
## 配置使用
模块按需引用
```csharp
[DependsOn(typeof(AbpBackgroundTasksDistributedLockingModule))]
public class YouProjectModule : AbpModule
{
// other
}
```

15
aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks.EventBus/README.md

@ -0,0 +1,15 @@
# LINGYUN.Abp.BackgroundTasks.EventBus
后台任务(队列)模块分布式事件模块,集成模块使应用程序具备处理作业事件能力
## 配置使用
模块按需引用
```csharp
[DependsOn(typeof(AbpBackgroundTasksEventBusModule))]
public class YouProjectModule : AbpModule
{
// other
}
```

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

@ -24,7 +24,7 @@
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\LINGYUN.Abp.BackgroundTasks\LINGYUN.Abp.BackgroundTasks.csproj" />
<ProjectReference Include="..\LINGYUN.Abp.BackgroundTasks.Activities\LINGYUN.Abp.BackgroundTasks.Activities.csproj" />
</ItemGroup>
</Project>

7
aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks.ExceptionHandling/LINGYUN/Abp/BackgroundTasks/ExceptionHandling/AbpBackgroundTasksExceptionHandlingModule.cs

@ -1,12 +1,13 @@
using LINGYUN.Abp.BackgroundTasks.Localization;
using LINGYUN.Abp.BackgroundTasks.Activities;
using LINGYUN.Abp.BackgroundTasks.Localization;
using Volo.Abp.Emailing;
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(AbpBackgroundTasksActivitiesModule))]
[DependsOn(typeof(AbpEmailingModule))]
public class AbpBackgroundTasksExceptionHandlingModule : AbpModule
{

25
aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks.ExceptionHandling/LINGYUN/Abp/BackgroundTasks/ExceptionHandling/ExceptionHandlingJobActionDefinitionProvider.cs

@ -0,0 +1,25 @@
using LINGYUN.Abp.BackgroundTasks.Activities;
using LINGYUN.Abp.BackgroundTasks.Localization;
using Volo.Abp.Localization;
namespace LINGYUN.Abp.BackgroundTasks.ExceptionHandling;
public class ExceptionHandlingJobActionDefinitionProvider : JobActionDefinitionProvider
{
public override void Define(IJobActionDefinitionContext context)
{
context.Add(
new JobActionDefinition(
JobExecutedFailedProvider.Name,
JobActionType.Failed,
L("JobExceptionNotifier"),
JobExecutedFailedProvider.Paramters,
L("JobExceptionNotifier"))
.WithProvider<JobExecutedFailedProvider>());
}
private static ILocalizableString L(string name)
{
return LocalizableString.Create<BackgroundTasksResource>(name);
}
}

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

@ -0,0 +1,144 @@
using JetBrains.Annotations;
using LINGYUN.Abp.BackgroundTasks.Activities;
using LINGYUN.Abp.BackgroundTasks.ExceptionHandling.Templates;
using LINGYUN.Abp.BackgroundTasks.Localization;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging.Abstractions;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Threading.Tasks;
using Volo.Abp.DependencyInjection;
using Volo.Abp.Emailing;
using Volo.Abp.Localization;
using Volo.Abp.MultiTenancy;
using Volo.Abp.TextTemplating;
namespace LINGYUN.Abp.BackgroundTasks.ExceptionHandling;
public class JobExecutedFailedProvider : JobExecutedProvider, ITransientDependency
{
public const string Name = "JobExecutedFailedProvider";
public readonly static IList<JobActionParamter> Paramters = new List<JobActionParamter>
{
new JobActionParamter(PropertyTo, L("DisplayName:PropertyTo"), L("Description:PropertyTo"), true),
new JobActionParamter(PropertySubject, L("DisplayName:PropertySubject"), L("Description:PropertySubject")),
new JobActionParamter(PropertyFrom, L("DisplayName:PropertyFrom"), L("Description:PropertyFrom")),
new JobActionParamter(PropertyBody, L("DisplayName:PropertyBody"), L("Description:PropertyBody")),
new JobActionParamter(PropertyTemplate, L("DisplayName:PropertyTemplate"), L("Description:PropertyTemplate")),
new JobActionParamter(PropertyContext, L("DisplayName:PropertyContext"), L("Description:PropertyContext")),
new JobActionParamter(PropertyCulture, L("DisplayName:PropertyCulture"), L("Description:PropertyCulture")),
};
public const string Prefix = "exception.";
public const string JobGroup = "ExceptionNotifier";
public const string PropertyFrom = Prefix + "from";
/// <summary>
/// 接收者
/// </summary>
public const string PropertyTo = Prefix + "to";
/// <summary>
/// 必须,邮件主体
/// </summary>
public const string PropertySubject = Prefix + "subject";
/// <summary>
/// 消息内容, 文本消息时必须
/// </summary>
public const string PropertyBody = Prefix + "body";
/// <summary>
/// 发送模板消息
/// </summary>
public const string PropertyTemplate = Prefix + "template";
/// <summary>
/// 可选, 模板消息中的上下文参数
/// </summary>
public const string PropertyContext = Prefix + "context";
/// <summary>
/// 可选, 模板消息中的区域性
/// </summary>
public const string PropertyCulture = Prefix + "culture";
public ILogger<JobExecutedFailedProvider> Logger { protected get; set; }
protected IEmailSender EmailSender { get; }
protected ITemplateRenderer TemplateRenderer { get; }
public JobExecutedFailedProvider(
IEmailSender emailSender,
ITemplateRenderer templateRenderer)
{
EmailSender = emailSender;
TemplateRenderer = templateRenderer;
Logger = NullLogger<JobExecutedFailedProvider>.Instance;
}
public override async Task NotifyErrorAsync([NotNull] JobActionExecuteContext context)
{
if (context.Action.Paramters.TryGetValue(PropertyTo, out var exceptionTo) &&
exceptionTo is string to)
{
var template = context.Action.Paramters.GetOrDefault(PropertyTemplate)?.ToString() ?? "";
var subject = context.Action.Paramters.GetOrDefault(PropertySubject)?.ToString() ?? "From job execute exception";
var from = context.Action.Paramters.GetOrDefault(PropertyFrom)?.ToString() ?? "";
var errorMessage = context.Event.EventData.Exception.GetBaseException().Message;
if (template.IsNullOrWhiteSpace())
{
// var message = eventData.Args.GetOrDefault(SendEmailJob.PropertyBody)?.ToString() ?? "";
// await EmailSender.SendAsync(from, to, subject, message, false);
// return;
// 默认使用内置模板发送错误
template = JobExceptionHandlingTemplates.JobExceptionNotifier;
}
var footer = context.Action.Paramters.GetOrDefault("footer")?.ToString() ?? $"Copyright to LY Colin © {context.Event.EventData.RunTime.Year}";
var model = new
{
Title = subject,
Id = context.Event.EventData.Key,
Group = context.Action.Paramters.GetOrDefault(nameof(JobInfo.Group)) ?? context.Event.EventData.Group,
Name = context.Action.Paramters.GetOrDefault(nameof(JobInfo.Name)) ?? context.Event.EventData.Name,
Type = context.Action.Paramters.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)),
Footer = footer,
};
var globalContext = new Dictionary<string, object>();
if (context.Action.Paramters.TryGetValue(PropertyContext, out var ctx) &&
ctx is string ctxStr && !ctxStr.IsNullOrWhiteSpace())
{
try
{
globalContext = JsonConvert.DeserializeObject<Dictionary<string, object>>(ctxStr);
}
catch { }
}
globalContext.AddIfNotContains(context.Action.Paramters);
var culture = context.Action.Paramters.GetOrDefault(PropertyCulture)?.ToString() ?? CultureInfo.CurrentCulture.Name;
var content = await TemplateRenderer.RenderAsync(
templateName: template,
model: model,
cultureName: culture,
globalContext: globalContext);
if (from.IsNullOrWhiteSpace())
{
await EmailSender.SendAsync(to, subject, content, true);
return;
}
await EmailSender.SendAsync(from, to, subject, content, true);
}
}
private static ILocalizableString L(string name)
{
return LocalizableString.Create<BackgroundTasksResource>(name);
}
}

132
aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks.ExceptionHandling/LINGYUN/Abp/BackgroundTasks/ExceptionHandling/JobFailedNotifierProvider.cs

@ -1,132 +0,0 @@
using JetBrains.Annotations;
using LINGYUN.Abp.BackgroundTasks.ExceptionHandling.Templates;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging.Abstractions;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Threading.Tasks;
using Volo.Abp.DependencyInjection;
using Volo.Abp.Emailing;
using Volo.Abp.MultiTenancy;
using Volo.Abp.TextTemplating;
namespace LINGYUN.Abp.BackgroundTasks.ExceptionHandling;
public class JobFailedNotifierProvider : IJobFailedNotifierProvider, ITransientDependency
{
public const string Prefix = "exception.";
public const string JobGroup = "ExceptionNotifier";
public const string PropertyFrom = "from";
/// <summary>
/// 接收者
/// </summary>
public const string PropertyTo = "to";
/// <summary>
/// 必须,邮件主体
/// </summary>
public const string PropertySubject = "subject";
/// <summary>
/// 消息内容, 文本消息时必须
/// </summary>
public const string PropertyBody = "body";
/// <summary>
/// 发送模板消息
/// </summary>
public const string PropertyTemplate = "template";
/// <summary>
/// 可选, 模板消息中的上下文参数
/// </summary>
public const string PropertyContext = "context";
/// <summary>
/// 可选, 模板消息中的区域性
/// </summary>
public const string PropertyCulture = "culture";
public ILogger<JobFailedNotifierProvider> Logger { protected get; set; }
protected IEmailSender EmailSender { get; }
protected ITemplateRenderer TemplateRenderer { get; }
public JobFailedNotifierProvider(
IEmailSender emailSender,
ITemplateRenderer templateRenderer)
{
EmailSender = emailSender;
TemplateRenderer = templateRenderer;
Logger = NullLogger<JobFailedNotifierProvider>.Instance;
}
public virtual async Task NotifyErrorAsync([NotNull] JobEventContext context)
{
var eventData = context.EventData;
// 异常所属分组不处理, 防止死循环
if (string.Equals(eventData.Group, JobGroup))
{
Logger.LogWarning($"There is a problem executing the job, reason: {eventData.Exception.Message}");
return;
}
var notifyKey = Prefix + PropertyTo;
if (eventData.Args.TryGetValue(notifyKey, out var exceptionTo) &&
exceptionTo is string to)
{
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())
{
// var message = eventData.Args.GetOrDefault(Prefix + SendEmailJob.PropertyBody)?.ToString() ?? "";
// await EmailSender.SendAsync(from, to, subject, message, false);
// return;
// 默认使用内置模板发送错误
template = JobExceptionHandlingTemplates.JobExceptionNotifier;
}
var footer = eventData.Args.GetOrDefault("footer")?.ToString() ?? $"Copyright to LY Colin © {eventData.RunTime.Year}";
var model = new
{
Title = subject,
Id = eventData.Key,
Group = eventData.Args.GetOrDefault(nameof(JobInfo.Group)) ?? eventData.Group,
Name = eventData.Args.GetOrDefault(nameof(JobInfo.Name)) ?? eventData.Name,
Type = eventData.Args.GetOrDefault(nameof(JobInfo.Type)) ?? eventData.Type.Name,
Triggertime = eventData.RunTime.ToString("yyyy-MM-dd HH:mm:ss"),
Message = errorMessage,
Tenantname = eventData.Args.GetOrDefault(nameof(IMultiTenant.TenantId)),
Footer = footer,
};
var globalContext = new Dictionary<string, object>();
if (eventData.Args.TryGetValue(Prefix + PropertyContext, out var ctx) &&
ctx is string ctxStr && !ctxStr.IsNullOrWhiteSpace())
{
try
{
globalContext = JsonConvert.DeserializeObject<Dictionary<string, object>>(ctxStr);
}
catch { }
}
globalContext.AddIfNotContains(eventData.Args);
var culture = eventData.Args.GetOrDefault(Prefix + PropertyCulture)?.ToString() ?? CultureInfo.CurrentCulture.Name;
var content = await TemplateRenderer.RenderAsync(
templateName: template,
model: model,
cultureName: culture,
globalContext: globalContext);
if (from.IsNullOrWhiteSpace())
{
await EmailSender.SendAsync(to, subject, content, true);
return;
}
await EmailSender.SendAsync(from, to, subject, content, true);
}
}
}

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

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

8
aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks.Jobs/LINGYUN.Abp.BackgroundTasks.Jobs.csproj

@ -8,6 +8,14 @@
<RootNamespace />
</PropertyGroup>
<ItemGroup>
<None Remove="LINGYUN\Abp\BackgroundTasks\Jobs\Localization\Resources\*.json" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="LINGYUN\Abp\BackgroundTasks\Jobs\Localization\Resources\*.json" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Volo.Abp.Emailing" Version="$(VoloAbpPackageVersion)" />
<PackageReference Include="Volo.Abp.Sms" Version="$(VoloAbpPackageVersion)" />

22
aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks.Jobs/LINGYUN/Abp/BackgroundTasks/Jobs/AbpBackgroundTasksJobsModule.cs

@ -1,10 +1,13 @@
using LINGYUN.Abp.Dapr.Client;
using LINGYUN.Abp.BackgroundTasks.Localization;
using LINGYUN.Abp.Dapr.Client;
using LINGYUN.Abp.Dapr.Client.DynamicProxying;
using Microsoft.Extensions.DependencyInjection;
using Volo.Abp.Emailing;
using Volo.Abp.Http.Client;
using Volo.Abp.Localization;
using Volo.Abp.Modularity;
using Volo.Abp.Sms;
using Volo.Abp.VirtualFileSystem;
namespace LINGYUN.Abp.BackgroundTasks.Jobs;
@ -12,6 +15,7 @@ namespace LINGYUN.Abp.BackgroundTasks.Jobs;
[DependsOn(typeof(AbpSmsModule))]
[DependsOn(typeof(AbpHttpClientModule))]
[DependsOn(typeof(AbpDaprClientModule))]
[DependsOn(typeof(AbpBackgroundTasksAbstractionsModule))]
public class AbpBackgroundTasksJobsModule : AbpModule
{
protected const string DontWrapResultField = "_AbpDontWrapResult";
@ -33,14 +37,16 @@ public class AbpBackgroundTasksJobsModule : AbpModule
public override void ConfigureServices(ServiceConfigurationContext context)
{
Configure<AbpBackgroundTasksOptions>(options =>
Configure<AbpVirtualFileSystemOptions>(options =>
{
options.AddProvider<ConsoleJob>(DefaultJobNames.ConsoleJob);
options.AddProvider<SendEmailJob>(DefaultJobNames.SendEmailJob);
options.AddProvider<SendSmsJob>(DefaultJobNames.SendSmsJob);
options.AddProvider<SleepJob>(DefaultJobNames.SleepJob);
options.AddProvider<ServiceInvocationJob>(DefaultJobNames.ServiceInvocationJob);
options.AddProvider<HttpRequestJob>(DefaultJobNames.HttpRequestJob);
options.FileSets.AddEmbedded<AbpBackgroundTasksJobsModule>();
});
Configure<AbpLocalizationOptions>(options =>
{
options.Resources
.Get<BackgroundTasksResource>()
.AddVirtualJson("/LINGYUN/Abp/BackgroundTasks/Jobs/Localization/Resources");
});
Configure<AbpDaprClientProxyOptions>(options =>

11
aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks.Jobs/LINGYUN/Abp/BackgroundTasks/Jobs/ConsoleJob.cs

@ -1,10 +1,21 @@
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
namespace LINGYUN.Abp.BackgroundTasks.Jobs;
public class ConsoleJob : IJobRunnable
{
#region Definition Paramters
public readonly static IReadOnlyList<JobDefinitionParamter> Paramters =
new List<JobDefinitionParamter>
{
new JobDefinitionParamter(PropertyMessage, LocalizableStatic.Create("Console:Message"))
};
#endregion
public const string PropertyMessage = "message";
public Task ExecuteAsync(JobRunnableContext context)
{

51
aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks.Jobs/LINGYUN/Abp/BackgroundTasks/Jobs/DefaultJobDefinitionProvider.cs

@ -0,0 +1,51 @@
namespace LINGYUN.Abp.BackgroundTasks.Jobs;
public class DefaultJobDefinitionProvider : JobDefinitionProvider
{
public override void Define(IJobDefinitionContext context)
{
context.Add(CreateDefaultJobs());
}
private static JobDefinition[] CreateDefaultJobs()
{
return new[]
{
new JobDefinition(
DefaultJobNames.SleepJob,
typeof(SleepJob),
LocalizableStatic.Create("SleepJob"),
SleepJob.Paramters),
new JobDefinition(
DefaultJobNames.ConsoleJob,
typeof(ConsoleJob),
LocalizableStatic.Create("ConsoleJob"),
ConsoleJob.Paramters),
new JobDefinition(
DefaultJobNames.SendSmsJob,
typeof(SendSmsJob),
LocalizableStatic.Create("SendSmsJob"),
SendSmsJob.Paramters),
new JobDefinition(
DefaultJobNames.SendEmailJob,
typeof(SendEmailJob),
LocalizableStatic.Create("SendEmailJob"),
SendEmailJob.Paramters),
new JobDefinition(
DefaultJobNames.HttpRequestJob,
typeof(HttpRequestJob),
LocalizableStatic.Create("HttpRequestJob"),
HttpRequestJob.Paramters),
new JobDefinition(
DefaultJobNames.ServiceInvocationJob,
typeof(ServiceInvocationJob),
LocalizableStatic.Create("ServiceInvocationJob"),
ServiceInvocationJob.Paramters),
};
}
}

24
aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks.Jobs/LINGYUN/Abp/BackgroundTasks/Jobs/HttpRequestJob.cs

@ -8,12 +8,34 @@ namespace LINGYUN.Abp.BackgroundTasks.Jobs;
public class HttpRequestJob : HttpRequestJobBase, IJobRunnable
{
#region Definition Paramters
public readonly static IReadOnlyList<JobDefinitionParamter> Paramters =
new List<JobDefinitionParamter>
{
new JobDefinitionParamter(
PropertyUrl,
LocalizableStatic.Create("Http:Url"),
required: true),
new JobDefinitionParamter(
PropertyMethod,
LocalizableStatic.Create("Http:Method"),
LocalizableStatic.Create("Http:MethodDesc"),
required: true),
new JobDefinitionParamter(PropertyData, LocalizableStatic.Create("Http:Data")),
new JobDefinitionParamter(PropertyContentType, LocalizableStatic.Create("Http:ContentType")),
new JobDefinitionParamter(PropertyHeaders, LocalizableStatic.Create("Http:Headers")),
new JobDefinitionParamter(PropertyCulture, LocalizableStatic.Create("Http:Culture")),
};
#endregion
public const string PropertyUrl = "url";
public const string PropertyMethod = "method";
public const string PropertyData = "data";
public const string PropertyContentType = "contentType";
public const string PropertyHeaders = "headers";
public const string PropertyToken = "token";
public virtual async Task ExecuteAsync(JobRunnableContext context)
{

12
aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks.Jobs/LINGYUN/Abp/BackgroundTasks/Jobs/LocalizableStatic.cs

@ -0,0 +1,12 @@
using LINGYUN.Abp.BackgroundTasks.Localization;
using Volo.Abp.Localization;
namespace LINGYUN.Abp.BackgroundTasks.Jobs;
internal static class LocalizableStatic
{
public static ILocalizableString Create(string name)
{
return LocalizableString.Create<BackgroundTasksResource>(name);
}
}

37
aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks.Jobs/LINGYUN/Abp/BackgroundTasks/Jobs/Localization/Resources/en.json

@ -0,0 +1,37 @@
{
"culture": "en",
"texts": {
"SleepJob": "Sleep Job",
"ConsoleJob": "Console Job",
"SendSmsJob": "Sms Job",
"SendEmailJob": "Email Job",
"HttpRequestJob": "Http Request Job",
"ServiceInvocationJob": "Service Invocation Job",
"Console:Message": "Message",
"Http:Url": "Url",
"Http:Method": "Method",
"Http:MethodDesc": "The request method can be GET, PUT, POST, PATCH, OPTIONS, or DELETE.",
"Http:Data": "Data",
"Http:ContentType": "Content Type",
"Http:Headers": "Headers",
"Http:Culture": "Culture",
"Http:Service": "Service",
"Http:Tenant": "Tenant",
"Http:Provider": "Provider",
"Http:ProviderDesc": "Interservice invocation program, optional scope: http、dapr.",
"Http:AppId": "App Id",
"Http:AppIdDesc": "App Id, This parameter takes effect only when the provider is dapr.",
"Sms:PhoneNumber": "Phone Number",
"Sms:Message": "Message",
"Sms:Properties": "Properties",
"Emailing:To": "To",
"Emailing:Subject": "Subject",
"Emailing:From": "From",
"Emailing:Body": "Body",
"Emailing:Template": "Template",
"Emailing:Model": "Model",
"Emailing:Context": "Context",
"Emailing:Culture": "Culture",
"Sleep:Delay": "Delay(ms)"
}
}

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

@ -0,0 +1,37 @@
{
"culture": "zh-Hans",
"texts": {
"SleepJob": "休眠作业",
"ConsoleJob": "控制台作业",
"SendSmsJob": "短信作业",
"SendEmailJob": "邮件作业",
"HttpRequestJob": "Http请求作业",
"ServiceInvocationJob": "远程调用作业",
"Console:Message": "消息",
"Http:Url": "请求路径",
"Http:Method": "请求方法",
"Http:MethodDesc": "请求方法,支持的格式为GET、PUT、POST、PATCH、OPTIONS、DELETE.",
"Http:Data": "传输数据",
"Http:ContentType": "内容类型",
"Http:Headers": "请求头",
"Http:Culture": "文化名称",
"Http:Service": "服务名称",
"Http:Tenant": "租户",
"Http:Provider": "调用方",
"Http:ProviderDesc": "服务间调用程序,可选范围: http、dapr.",
"Http:AppId": "应用标识",
"Http:AppIdDesc": "应用标识,仅限调用方为dapr时生效.",
"Sms:PhoneNumber": "手机号码",
"Sms:Message": "消息内容",
"Sms:Properties": "消息参数",
"Emailing:To": "收件地址",
"Emailing:Subject": "邮件标题",
"Emailing:From": "发送方名称",
"Emailing:Body": "发送内容",
"Emailing:Template": "邮件模板",
"Emailing:Model": "数据",
"Emailing:Context": "全局参数",
"Emailing:Culture": "文化名称",
"Sleep:Delay": "延迟(ms)"
}
}

19
aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks.Jobs/LINGYUN/Abp/BackgroundTasks/Jobs/SendEmailJob.cs

@ -9,6 +9,25 @@ namespace LINGYUN.Abp.BackgroundTasks.Jobs;
public class SendEmailJob : IJobRunnable
{
#region Definition Paramters
public readonly static IReadOnlyList<JobDefinitionParamter> Paramters =
new List<JobDefinitionParamter>
{
new JobDefinitionParamter(PropertyTo, LocalizableStatic.Create("Emailing:To"), required: true),
new JobDefinitionParamter(PropertySubject, LocalizableStatic.Create("Emailing:Subject"), required: true),
new JobDefinitionParamter(PropertyFrom, LocalizableStatic.Create("Emailing:From")),
new JobDefinitionParamter(PropertyBody, LocalizableStatic.Create("Emailing:Body")),
new JobDefinitionParamter(PropertyTemplate, LocalizableStatic.Create("Emailing:Template")),
new JobDefinitionParamter(PropertyModel, LocalizableStatic.Create("Emailing:Model")),
new JobDefinitionParamter(PropertyContext, LocalizableStatic.Create("Emailing:Context")),
new JobDefinitionParamter(PropertyCulture, LocalizableStatic.Create("Emailing:Culture")),
};
#endregion
public const string PropertyFrom = "from";
/// <summary>
/// 接收者

13
aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks.Jobs/LINGYUN/Abp/BackgroundTasks/Jobs/SendSmsJob.cs

@ -7,6 +7,19 @@ namespace LINGYUN.Abp.BackgroundTasks.Jobs;
public class SendSmsJob : IJobRunnable
{
#region Definition Paramters
public readonly static IReadOnlyList<JobDefinitionParamter> Paramters =
new List<JobDefinitionParamter>
{
new JobDefinitionParamter(PropertyPhoneNumber, LocalizableStatic.Create("Sms:PhoneNumber"), required: true),
new JobDefinitionParamter(PropertyMessage, LocalizableStatic.Create("Sms:Message"), required: true),
new JobDefinitionParamter(PropertyProperties, LocalizableStatic.Create("Sms:Properties")),
};
#endregion
public const string PropertyPhoneNumber = "phoneNumber";
public const string PropertyMessage = "message";
public const string PropertyProperties = "properties";

17
aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks.Jobs/LINGYUN/Abp/BackgroundTasks/Jobs/ServiceInvocationJob.cs

@ -20,6 +20,23 @@ namespace LINGYUN.Abp.BackgroundTasks.Jobs;
public class ServiceInvocationJob : IJobRunnable
{
#region Definition Paramters
public readonly static IReadOnlyList<JobDefinitionParamter> Paramters =
new List<JobDefinitionParamter>
{
new JobDefinitionParamter(PropertyService, LocalizableStatic.Create("Http:Service"), required: true),
new JobDefinitionParamter(PropertyMethod, LocalizableStatic.Create("Http:Method"), required: true),
new JobDefinitionParamter(PropertyData, LocalizableStatic.Create("Http:Data")),
new JobDefinitionParamter(PropertyCulture, LocalizableStatic.Create("Http:Culture")),
new JobDefinitionParamter(PropertyTenant, LocalizableStatic.Create("Http:Tenant")),
new JobDefinitionParamter(PropertyProvider, LocalizableStatic.Create("Http:Provider"), LocalizableStatic.Create("Http:ProviderDesc")),
new JobDefinitionParamter(PropertyAppId, LocalizableStatic.Create("Http:AppId"), LocalizableStatic.Create("Http:AppIdDesc")),
};
#endregion
// 必须, 接口类型
public const string PropertyService = "service";
// 必须, 接口方法名称

15
aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks.Jobs/LINGYUN/Abp/BackgroundTasks/Jobs/SleepJob.cs

@ -1,13 +1,26 @@
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
namespace LINGYUN.Abp.BackgroundTasks.Jobs;
public class SleepJob : IJobRunnable
{
#region Definition Paramters
public readonly static IReadOnlyList<JobDefinitionParamter> Paramters =
new List<JobDefinitionParamter>
{
new JobDefinitionParamter(PropertyDelay, LocalizableStatic.Create("Sleep:Delay"))
};
#endregion
public const string PropertyDelay = "delay";
public async Task ExecuteAsync(JobRunnableContext context)
{
context.JobData.TryGetValue("Delay", out var sleep);
context.JobData.TryGetValue(PropertyDelay, out var sleep);
Console.WriteLine($"[{DateTime.Now:yyyy-MM-dd HH:mm:ss}] - Sleep {sleep ?? 20000} milliseconds.");

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

@ -0,0 +1,24 @@
# LINGYUN.Abp.BackgroundTasks.Jobs
后台任务(队列)常用作业模块
## 作业列表
* [ConsoleJob](./LINGYUN/Abp/BackgroundTasks/Jobs/ConsoleJob): 控制台输出
* [HttpRequestJob](./LINGYUN/Abp/BackgroundTasks/Jobs/HttpRequestJob): Http请求
* [SendEmailJob](./LINGYUN/Abp/BackgroundTasks/Jobs/SendEmailJob): 发送邮件
* [SendSmsJob](./LINGYUN/Abp/BackgroundTasks/Jobs/SendSmsJob): 发送短信
* [ServiceInvocationJob](./LINGYUN/Abp/BackgroundTasks/Jobs/ServiceInvocationJob): 服务间调用(Http请求的扩展)
* [SleepJob](./LINGYUN/Abp/BackgroundTasks/Jobs/SleepJob): 休眠,使作业延期执行
## 配置使用
模块按需引用
```csharp
[DependsOn(typeof(AbpBackgroundTasksJobsModule))]
public class YouProjectModule : AbpModule
{
// other
}
```

2
aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks.Quartz/LINGYUN/Abp/BackgroundTasks/Quartz/IQuartzJobExecutorProvider.cs → aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks.Quartz/LINGYUN/Abp/BackgroundTasks/Quartz/IQuartzJobCreator.cs

@ -2,7 +2,7 @@
namespace LINGYUN.Abp.BackgroundTasks.Quartz;
public interface IQuartzJobExecutorProvider
public interface IQuartzJobCreator
{
#nullable enable
IJobDetail? CreateJob(JobInfo job);

36
aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks.Quartz/LINGYUN/Abp/BackgroundTasks/Quartz/QuartzJobExecutorProvider.cs → aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks.Quartz/LINGYUN/Abp/BackgroundTasks/Quartz/QuartzJobCreator.cs

@ -1,46 +1,50 @@
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging.Abstractions;
using Microsoft.Extensions.Options;
using Quartz;
using System;
using System.Collections.Generic;
using Volo.Abp.DependencyInjection;
using Volo.Abp.Timing;
namespace LINGYUN.Abp.BackgroundTasks.Quartz;
public class QuartzJobExecutorProvider : IQuartzJobExecutorProvider, ISingletonDependency
public class QuartzJobCreator : IQuartzJobCreator, ISingletonDependency
{
public ILogger<QuartzJobExecutorProvider> Logger { protected get; set; }
public ILogger<QuartzJobCreator> Logger { protected get; set; }
protected IClock Clock { get; }
protected AbpBackgroundTasksOptions Options { get; }
protected IQuartzKeyBuilder KeyBuilder { get; }
public QuartzJobExecutorProvider(
protected IJobDefinitionManager JobDefinitionManager { get; }
public QuartzJobCreator(
IClock clock,
IQuartzKeyBuilder keyBuilder,
IOptions<AbpBackgroundTasksOptions> options)
IJobDefinitionManager jobDefinitionManager)
{
Clock = clock;
Options = options.Value;
KeyBuilder = keyBuilder;
JobDefinitionManager = jobDefinitionManager;
Logger = NullLogger<QuartzJobExecutorProvider>.Instance;
Logger = NullLogger<QuartzJobCreator>.Instance;
}
public IJobDetail CreateJob(JobInfo job)
{
var jobType = Options.JobProviders.GetOrDefault(job.Type) ?? Type.GetType(job.Type);
var jobDefinition = JobDefinitionManager.GetOrNull(job.Type);
var jobType = jobDefinition?.JobType ?? Type.GetType(job.Type);
if (jobType == null)
{
Logger.LogWarning($"The task: {job.Group} - {job.Name}: {job.Type} is not registered and cannot create an instance of the performer type.");
return null;
}
//Logger.LogWarning($"The task: {job.Group} - {job.Name}: {job.Type} is not registered and cannot create an instance of the performer type.");
//return null;
if (!typeof(IJob).IsAssignableFrom(jobType))
// 运行时搜寻本地作业
jobType = typeof(QuartzJobSearchJobAdapter);
}
else
{
var adapterType = typeof(QuartzJobSimpleAdapter<>);
jobType = adapterType.MakeGenericType(jobType);
if (!typeof(IJob).IsAssignableFrom(jobType))
{
var adapterType = typeof(QuartzJobSimpleAdapter<>);
jobType = adapterType.MakeGenericType(jobType);
}
}
// 改为 JobId作为名称

10
aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks.Quartz/LINGYUN/Abp/BackgroundTasks/Quartz/QuartzJobListener.cs

@ -33,12 +33,14 @@ public class QuartzJobListener : JobListenerSupport, ISingletonDependency
public override Task JobExecutionVetoed(IJobExecutionContext context, CancellationToken cancellationToken = default)
{
var jobType = context.JobDetail.JobType;
if (jobType.IsGenericType)
var jobName = context.MergedJobDataMap.Get(nameof(JobInfo.Name))?.ToString();
if (jobName.IsNullOrWhiteSpace())
{
jobType = jobType.GetGenericArguments()[0];
var jobType = context.JobDetail.JobType;
jobName = !jobType.IsGenericType ? jobType.Name : jobType.GetGenericArguments()[0].Name;
}
Logger.LogWarning($"The task {jobType.Name} could not be performed...");
Logger.LogWarning($"The task {jobName} could not be performed...");
return Task.FromResult(-1);
}

14
aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks.Quartz/LINGYUN/Abp/BackgroundTasks/Quartz/QuartzJobScheduler.cs

@ -16,18 +16,18 @@ public class QuartzJobScheduler : IJobScheduler, IJobPublisher, ISingletonDepend
protected IJobStore JobStore { get; }
protected IScheduler Scheduler { get; }
protected IQuartzKeyBuilder KeyBuilder { get; }
protected IQuartzJobExecutorProvider QuartzJobExecutor { get; }
protected IQuartzJobCreator QuartzJobCreator { get; }
public QuartzJobScheduler(
IJobStore jobStore,
IScheduler scheduler,
IQuartzKeyBuilder keyBuilder,
IQuartzJobExecutorProvider quartzJobExecutor)
IQuartzJobCreator quartzJobCreator)
{
JobStore = jobStore;
Scheduler = scheduler;
KeyBuilder = keyBuilder;
QuartzJobExecutor = quartzJobExecutor;
QuartzJobCreator = quartzJobCreator;
}
public virtual async Task<bool> ExistsAsync(JobInfo job, CancellationToken cancellationToken = default)
@ -61,13 +61,13 @@ public class QuartzJobScheduler : IJobScheduler, IJobPublisher, ISingletonDepend
return false;
}
var jobDetail = QuartzJobExecutor.CreateJob(job);
var jobDetail = QuartzJobCreator.CreateJob(job);
if (jobDetail == null)
{
return false;
}
var jobTrigger = QuartzJobExecutor.CreateTrigger(job);
var jobTrigger = QuartzJobCreator.CreateTrigger(job);
if (jobTrigger == null)
{
return false;
@ -83,13 +83,13 @@ public class QuartzJobScheduler : IJobScheduler, IJobPublisher, ISingletonDepend
var jobDictionary = new Dictionary<IJobDetail, IReadOnlyCollection<ITrigger>>();
foreach (var job in jobs)
{
var jobDetail = QuartzJobExecutor.CreateJob(job);
var jobDetail = QuartzJobCreator.CreateJob(job);
if (jobDetail == null)
{
continue;
}
var jobTrigger = QuartzJobExecutor.CreateTrigger(job);
var jobTrigger = QuartzJobCreator.CreateTrigger(job);
if (jobTrigger == null)
{
continue;

40
aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks.Quartz/LINGYUN/Abp/BackgroundTasks/Quartz/QuartzJobSearchJobAdapter.cs

@ -0,0 +1,40 @@
using Microsoft.Extensions.DependencyInjection;
using Quartz;
using System.Collections.Immutable;
using System.Threading.Tasks;
namespace LINGYUN.Abp.BackgroundTasks.Quartz;
public class QuartzJobSearchJobAdapter : IJob
{
protected IServiceScopeFactory ServiceScopeFactory { get; }
protected IJobDefinitionManager JobDefinitionManager { get; }
public QuartzJobSearchJobAdapter(
IServiceScopeFactory serviceScopeFactory,
IJobDefinitionManager jobDefinitionManager)
{
ServiceScopeFactory = serviceScopeFactory;
JobDefinitionManager = jobDefinitionManager;
}
public async virtual Task Execute(IJobExecutionContext context)
{
var jobType = context.MergedJobDataMap.GetString(nameof(JobInfo.Type));
var jobDefinition = JobDefinitionManager.Get(jobType);
using var scope = ServiceScopeFactory.CreateScope();
var jobExecuter = scope.ServiceProvider.GetRequiredService<IJobRunnableExecuter>();
var jobContext = new JobRunnableContext(
jobDefinition.JobType,
scope.ServiceProvider,
context.MergedJobDataMap.ToImmutableDictionary(),
getCache: (key) => context.Get(key),
setCache: context.Put);
await jobExecuter.ExecuteAsync(jobContext);
context.Result = jobContext.Result;
}
}

19
aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks.Quartz/LINGYUN/Abp/BackgroundTasks/Quartz/QuartzTriggerListener.cs

@ -1,12 +1,11 @@
using Microsoft.Extensions.Options;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging.Abstractions;
using Microsoft.Extensions.Options;
using Quartz;
using Quartz.Listener;
using System.Threading;
using System.Threading.Tasks;
using Volo.Abp.DependencyInjection;
using System;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging.Abstractions;
namespace LINGYUN.Abp.BackgroundTasks.Quartz;
@ -36,15 +35,13 @@ public class QuartzTriggerListener : TriggerListenerSupport, ISingletonDependenc
IJobExecutionContext context,
CancellationToken cancellationToken = default)
{
if (!Options.NodeName.IsNullOrWhiteSpace())
context.MergedJobDataMap.TryGetValue(nameof(JobInfo.NodeName), out var jobNode);
if (!Equals(Options.NodeName, jobNode))
{
context.MergedJobDataMap.TryGetValue(nameof(JobInfo.NodeName), out var jobNode);
if (!Equals(Options.NodeName, jobNode))
{
Logger.LogDebug("the job does not belong to the current node and will be ignored by the scheduler.");
return true;
}
Logger.LogDebug("the job does not belong to the current node and will be ignored by the scheduler.");
return true;
}
context.MergedJobDataMap.TryGetValue(nameof(JobInfo.Id), out var jobId);
context.MergedJobDataMap.TryGetValue(nameof(JobInfo.LockTimeOut), out var lockTime);
if (jobId != null && lockTime != null && int.TryParse(lockTime.ToString(), out var time) && time > 0)

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

@ -8,12 +8,19 @@
<RootNamespace />
</PropertyGroup>
<ItemGroup>
<None Remove="LINGYUN\Abp\BackgroundTasks\Localization\Resources\*.json" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="LINGYUN\Abp\BackgroundTasks\Localization\Resources\*.json" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Volo.Abp.Auditing" Version="$(VoloAbpPackageVersion)" />
<PackageReference Include="Volo.Abp.BackgroundJobs.Abstractions" Version="$(VoloAbpPackageVersion)" />
<PackageReference Include="Volo.Abp.BackgroundWorkers" Version="$(VoloAbpPackageVersion)" />
<PackageReference Include="Volo.Abp.Caching" Version="$(VoloAbpPackageVersion)" />
<PackageReference Include="Volo.Abp.DistributedLocking.Abstractions" Version="$(VoloAbpPackageVersion)" />
<PackageReference Include="Volo.Abp.Guids" Version="$(VoloAbpPackageVersion)" />
</ItemGroup>

6
aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks/LINGYUN/Abp/BackgroundTasks/AbpBackgroundTasksModule.cs

@ -5,7 +5,6 @@ using System.Collections.Generic;
using Volo.Abp.Auditing;
using Volo.Abp.BackgroundJobs;
using Volo.Abp.BackgroundWorkers;
using Volo.Abp.DistributedLocking;
using Volo.Abp.Guids;
using Volo.Abp.Localization;
using Volo.Abp.Modularity;
@ -14,11 +13,9 @@ using Volo.Abp.VirtualFileSystem;
namespace LINGYUN.Abp.BackgroundTasks;
[DependsOn(typeof(AbpAuditingModule))]
[DependsOn(typeof(AbpLocalizationModule))]
[DependsOn(typeof(AbpBackgroundTasksAbstractionsModule))]
[DependsOn(typeof(AbpBackgroundJobsAbstractionsModule))]
[DependsOn(typeof(AbpBackgroundWorkersModule))]
[DependsOn(typeof(AbpDistributedLockingAbstractionsModule))]
[DependsOn(typeof(AbpGuidsModule))]
public class AbpBackgroundTasksModule : AbpModule
{
@ -37,7 +34,7 @@ public class AbpBackgroundTasksModule : AbpModule
Configure<AbpLocalizationOptions>(options =>
{
options.Resources
.Add<BackgroundTasksResource>("en")
.Get<BackgroundTasksResource>()
.AddVirtualJson("/LINGYUN/Abp/BackgroundTasks/Localization/Resources");
});
@ -45,7 +42,6 @@ public class AbpBackgroundTasksModule : AbpModule
{
options.JobMonitors.AddIfNotContains(typeof(JobExecutedEvent));
options.JobMonitors.AddIfNotContains(typeof(JobLogEvent));
options.JobMonitors.AddIfNotContains(typeof(JobNotifierEvent));
});
}
}

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

@ -94,7 +94,7 @@ public class BackgroundWorkerAdapter<TWorker> : BackgroundWorkerBase, IBackgroun
{
if (_doWorkAsyncMethod != null)
{
await(Task) _doWorkAsyncMethod.Invoke(asyncWorker, new object[] { workerContext });
await(Task)_doWorkAsyncMethod.Invoke(asyncWorker, new object[] { workerContext });
}
break;

0
aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks.Abstractions/LINGYUN/Abp/BackgroundTasks/DefaultJobLockProvider.cs → aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks/LINGYUN/Abp/BackgroundTasks/DefaultJobLockProvider.cs

0
aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks.Abstractions/LINGYUN/Abp/BackgroundTasks/IJobLockProvider.cs → aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks/LINGYUN/Abp/BackgroundTasks/IJobLockProvider.cs

1
aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks/LINGYUN/Abp/BackgroundTasks/Internal/BackgroundCleaningJob.cs

@ -7,6 +7,7 @@ using Volo.Abp.MultiTenancy;
namespace LINGYUN.Abp.BackgroundTasks.Internal;
[DisableAuditing]
[DisableJobAction]
public class BackgroundCleaningJob : IJobRunnable
{
public virtual async Task ExecuteAsync(JobRunnableContext context)

1
aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks/LINGYUN/Abp/BackgroundTasks/Internal/BackgroundPollingJob.cs

@ -8,6 +8,7 @@ using Volo.Abp.MultiTenancy;
namespace LINGYUN.Abp.BackgroundTasks.Internal;
[DisableAuditing]
[DisableJobAction]
public class BackgroundPollingJob : IJobRunnable
{
public virtual async Task ExecuteAsync(JobRunnableContext context)

32
aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks/LINGYUN/Abp/BackgroundTasks/Internal/JobNotifierEvent.cs

@ -1,32 +0,0 @@
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using System;
using System.Threading.Tasks;
using Volo.Abp.DependencyInjection;
namespace LINGYUN.Abp.BackgroundTasks.Internal;
public class JobNotifierEvent : JobEventBase<JobNotifierEvent>, ITransientDependency
{
protected async override Task OnJobAfterExecutedAsync(JobEventContext context)
{
try
{
var notifier = context.ServiceProvider.GetRequiredService<IJobExecutedNotifier>();
if (context.EventData.Exception != null)
{
await notifier.NotifyErrorAsync(context);
}
else
{
await notifier.NotifySuccessAsync(context);
}
await notifier.NotifyComplateAsync(context);
}
catch (Exception ex)
{
Logger.LogWarning($"An exception thow with job notify: {ex.Message}");
}
}
}

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

@ -1,5 +1,7 @@
using Microsoft.Extensions.DependencyInjection;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Volo.Abp.DependencyInjection;
using Volo.Abp.MultiTenancy;

14
aspnet-core/modules/task-management/LINGYUN.Abp.TaskManagement.Application.Contracts/LINGYUN/Abp/TaskManagement/BackgroundJobActionCreateDto.cs

@ -0,0 +1,14 @@
using System.ComponentModel.DataAnnotations;
using Volo.Abp.Validation;
namespace LINGYUN.Abp.TaskManagement;
public class BackgroundJobActionCreateDto : BackgroundJobActionCreateOrUpdateDto
{
/// <summary>
/// 名称
/// </summary>
[Required]
[DynamicStringLength(typeof(BackgroundJobActionConsts), nameof(BackgroundJobActionConsts.MaxNameLength))]
public string Name { get; set; }
}

20
aspnet-core/modules/task-management/LINGYUN.Abp.TaskManagement.Application.Contracts/LINGYUN/Abp/TaskManagement/BackgroundJobActionCreateOrUpdateDto.cs

@ -0,0 +1,20 @@
using Volo.Abp.Data;
namespace LINGYUN.Abp.TaskManagement;
public abstract class BackgroundJobActionCreateOrUpdateDto
{
/// <summary>
/// 是否启用
/// </summary>
public bool IsEnabled { get; set; }
/// <summary>
/// 参数
/// </summary>
public ExtraPropertyDictionary Paramters { get; set; }
public BackgroundJobActionCreateOrUpdateDto()
{
Paramters = new ExtraPropertyDictionary();
}
}

28
aspnet-core/modules/task-management/LINGYUN.Abp.TaskManagement.Application.Contracts/LINGYUN/Abp/TaskManagement/BackgroundJobActionDefinitionDto.cs

@ -0,0 +1,28 @@
using LINGYUN.Abp.BackgroundTasks;
using System.Collections.Generic;
namespace LINGYUN.Abp.TaskManagement;
public class BackgroundJobActionDefinitionDto
{
/// <summary>
/// 名称
/// </summary>
public string Name { get; set; }
/// <summary>
/// 类型
/// </summary>
public JobActionType Type { get; set; }
/// <summary>
/// 显示名称
/// </summary>
public string DisplayName { get; set; }
/// <summary>
/// 描述
/// </summary>
public string Description { get; set; }
/// <summary>
/// 参数列表
/// </summary>
public IList<BackgroundJobActionParamterDto> Paramters { get; set; }
}

25
aspnet-core/modules/task-management/LINGYUN.Abp.TaskManagement.Application.Contracts/LINGYUN/Abp/TaskManagement/BackgroundJobActionDto.cs

@ -0,0 +1,25 @@
using System;
using Volo.Abp.Application.Dtos;
using Volo.Abp.Data;
namespace LINGYUN.Abp.TaskManagement;
public class BackgroundJobActionDto : EntityDto<Guid>
{
/// <summary>
/// 作业标识
/// </summary>
public string JobId { get; set; }
/// <summary>
/// 名称
/// </summary>
public string Name { get; set; }
/// <summary>
/// 是否启用
/// </summary>
public bool IsEnabled { get; set; }
/// <summary>
/// 参数
/// </summary>
public ExtraPropertyDictionary Paramters { get; set; }
}

8
aspnet-core/modules/task-management/LINGYUN.Abp.TaskManagement.Application.Contracts/LINGYUN/Abp/TaskManagement/BackgroundJobActionGetDefinitionsInput.cs

@ -0,0 +1,8 @@
using LINGYUN.Abp.BackgroundTasks;
namespace LINGYUN.Abp.TaskManagement;
public class BackgroundJobActionGetDefinitionsInput
{
public JobActionType? Type { get; set; }
}

Some files were not shown because too many files changed in this diff

Loading…
Cancel
Save