Browse Source

feat(tasks): perfect management api.

pull/457/head
cKey 4 years ago
parent
commit
f307fe51ee
  1. 104
      aspnet-core/LINGYUN.MicroService.TaskManagement.sln
  2. 45
      aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks.Abstractions/LINGYUN/Abp/BackgroundTasks/AbpBackgroundTaskConcurrentException.cs
  3. 14
      aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks.Quartz/LINGYUN/Abp/BackgroundTasks/Quartz/QuartzJobConcurrentAdapter.cs
  4. 5
      aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks.Quartz/LINGYUN/Abp/BackgroundTasks/Quartz/QuartzJobExecutorProvider.cs
  5. 11
      aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks.Quartz/LINGYUN/Abp/BackgroundTasks/Quartz/QuartzJobListener.cs
  6. 2
      aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks/LINGYUN.Abp.BackgroundTasks.csproj
  7. 2
      aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks/LINGYUN/Abp/BackgroundTasks/AbpBackgroundTasksModule.cs
  8. 2
      aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks/LINGYUN/Abp/BackgroundTasks/Internal/BackgroundCleaningJob.cs
  9. 1
      aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks/LINGYUN/Abp/BackgroundTasks/Internal/DefaultBackgroundWorker.cs
  10. 8
      aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks/LINGYUN/Abp/BackgroundTasks/Internal/JobExecutedEvent.cs
  11. 3
      aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks/LINGYUN/Abp/BackgroundTasks/Internal/JobLogEvent.cs
  12. 15
      aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks/LINGYUN/Abp/BackgroundTasks/JobRunnableExecuter.cs
  13. 16
      aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks/LINGYUN/Abp/BackgroundTasks/Primitives/SleepJob.cs
  14. 1
      aspnet-core/modules/task-management/LINGYUN.Abp.TaskManagement.Application.Contracts/LINGYUN.Abp.TaskManagement.Application.Contracts.csproj
  15. 1
      aspnet-core/modules/task-management/LINGYUN.Abp.TaskManagement.Application.Contracts/LINGYUN/Abp/TaskManagement/BackgroundJobLogGetListInput.cs
  16. 3
      aspnet-core/modules/task-management/LINGYUN.Abp.TaskManagement.Application.Contracts/LINGYUN/Abp/TaskManagement/IBackgroundJobLogAppService.cs
  17. 60
      aspnet-core/modules/task-management/LINGYUN.Abp.TaskManagement.Application.Contracts/LINGYUN/Abp/TaskManagement/Permissions/TaskManagementPermissionDefinitionProvider.cs
  18. 6
      aspnet-core/modules/task-management/LINGYUN.Abp.TaskManagement.Application.Contracts/LINGYUN/Abp/TaskManagement/Permissions/TaskManagementPermissions.cs
  19. 8
      aspnet-core/modules/task-management/LINGYUN.Abp.TaskManagement.Application.Contracts/LINGYUN/Abp/TaskManagement/TaskManagementRemoteServiceConsts.cs
  20. 53
      aspnet-core/modules/task-management/LINGYUN.Abp.TaskManagement.Application/LINGYUN/Abp/TaskManagement/BackgroundJobLogAppService.cs
  21. 1
      aspnet-core/modules/task-management/LINGYUN.Abp.TaskManagement.Application/LINGYUN/Abp/TaskManagement/TaskManagementApplicationMapperProfile.cs
  22. 1
      aspnet-core/modules/task-management/LINGYUN.Abp.TaskManagement.Domain.Shared/LINGYUN/Abp/TaskManagement/BackgroundJobInfoConsts.cs
  23. 12
      aspnet-core/modules/task-management/LINGYUN.Abp.TaskManagement.Domain.Shared/LINGYUN/Abp/TaskManagement/Localization/Resources/en.json
  24. 12
      aspnet-core/modules/task-management/LINGYUN.Abp.TaskManagement.Domain.Shared/LINGYUN/Abp/TaskManagement/Localization/Resources/zh-Hans.json
  25. 29
      aspnet-core/modules/task-management/LINGYUN.Abp.TaskManagement.Domain/LINGYUN/Abp/TaskManagement/BackgroundJobInfo.cs
  26. 15
      aspnet-core/modules/task-management/LINGYUN.Abp.TaskManagement.Domain/LINGYUN/Abp/TaskManagement/BackgroundJobLog.cs
  27. 37
      aspnet-core/modules/task-management/LINGYUN.Abp.TaskManagement.Domain/LINGYUN/Abp/TaskManagement/BackgroundJobManager.cs
  28. 5
      aspnet-core/modules/task-management/LINGYUN.Abp.TaskManagement.Domain/LINGYUN/Abp/TaskManagement/BackgroundJobStore.cs
  29. 2
      aspnet-core/modules/task-management/LINGYUN.Abp.TaskManagement.EntityFrameworkCore/LINGYUN/Abp/TaskManagement/EntityFrameworkCore/EfCoreBackgroundJobInfoRepository.cs
  30. 3
      aspnet-core/modules/task-management/LINGYUN.Abp.TaskManagement.EntityFrameworkCore/LINGYUN/Abp/TaskManagement/EntityFrameworkCore/TaskManagementDbContextModelCreatingExtensions.cs
  31. 84
      aspnet-core/modules/task-management/LINGYUN.Abp.TaskManagement.HttpApi/LINGYUN/Abp/TaskManagement/BackgroundJobInfoController.cs
  32. 44
      aspnet-core/modules/task-management/LINGYUN.Abp.TaskManagement.HttpApi/LINGYUN/Abp/TaskManagement/BackgroundJobLogController.cs
  33. 12
      aspnet-core/modules/task-management/LINGYUN.Abp.TaskManagement.HttpApi/LINGYUN/Abp/TaskManagement/TaskManagementController.cs
  34. 188
      aspnet-core/services/LY.MicroService.TaskManagement.HttpApi.Host/Migrations/20220109030916_Add-Module-Task-Management.Designer.cs
  35. 108
      aspnet-core/services/LY.MicroService.TaskManagement.HttpApi.Host/Migrations/20220109030916_Add-Module-Task-Management.cs
  36. 193
      aspnet-core/services/LY.MicroService.TaskManagement.HttpApi.Host/Migrations/20220109033926_Add-Field-Result-With-Background-Job-Info.Designer.cs
  37. 27
      aspnet-core/services/LY.MicroService.TaskManagement.HttpApi.Host/Migrations/20220109033926_Add-Field-Result-With-Background-Job-Info.cs
  38. 191
      aspnet-core/services/LY.MicroService.TaskManagement.HttpApi.Host/Migrations/TaskManagementMigrationsDbContextModelSnapshot.cs
  39. 8
      aspnet-core/services/LY.MicroService.TaskManagement.HttpApi.Host/TaskManagementHttpApiHostModule.cs
  40. 2
      aspnet-core/services/LY.MicroService.TaskManagement.HttpApi.Host/appsettings.Development.json
  41. 2
      aspnet-core/services/LY.MicroService.TaskManagement.HttpApi.Host/appsettings.json

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

@ -0,0 +1,104 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.0.31903.59
MinimumVisualStudioVersion = 10.0.40219.1
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "host", "host", "{8DA8A2EE-0B26-487E-A6C4-518906E92B1B}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{C38EB7EF-BAE9-4129-862A-71C652B81775}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tests", "tests", "{77341F31-F54C-436A-AF8D-F78D91303C45}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LINGYUN.Abp.TaskManagement.Domain.Shared", "modules\task-management\LINGYUN.Abp.TaskManagement.Domain.Shared\LINGYUN.Abp.TaskManagement.Domain.Shared.csproj", "{691CD138-9FFA-4988-BAC4-A32F0DAE1090}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LINGYUN.Abp.TaskManagement.Domain", "modules\task-management\LINGYUN.Abp.TaskManagement.Domain\LINGYUN.Abp.TaskManagement.Domain.csproj", "{8873A651-4F83-43B3-A34E-7AAA8A3ED4CF}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LINGYUN.Abp.TaskManagement.Application.Contracts", "modules\task-management\LINGYUN.Abp.TaskManagement.Application.Contracts\LINGYUN.Abp.TaskManagement.Application.Contracts.csproj", "{D5EC4CA0-7E16-4D17-B08E-E162EF332C77}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LINGYUN.Abp.TaskManagement.Application", "modules\task-management\LINGYUN.Abp.TaskManagement.Application\LINGYUN.Abp.TaskManagement.Application.csproj", "{09039DDF-5B0E-4670-8055-CC0BE82D4D2C}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LINGYUN.Abp.TaskManagement.HttpApi", "modules\task-management\LINGYUN.Abp.TaskManagement.HttpApi\LINGYUN.Abp.TaskManagement.HttpApi.csproj", "{283B0039-F67C-41F7-B554-DF5EE9178C4A}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LINGYUN.Abp.TaskManagement.EntityFrameworkCore", "modules\task-management\LINGYUN.Abp.TaskManagement.EntityFrameworkCore\LINGYUN.Abp.TaskManagement.EntityFrameworkCore.csproj", "{B8AB5E9B-9711-470E-8072-7444579EC5F6}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{C99728F6-FB3C-4D26-8917-1D30725209B9}"
ProjectSection(SolutionItems) = preProject
.editorconfig = .editorconfig
EndProjectSection
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "provider", "provider", "{385578CC-C0F1-4377-A7A2-682B8F416234}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LINGYUN.Abp.BackgroundTasks", "modules\task-management\LINGYUN.Abp.BackgroundTasks\LINGYUN.Abp.BackgroundTasks.csproj", "{AC0B4342-9C9B-41E6-9646-E505C763EE77}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LINGYUN.Abp.BackgroundTasks.Quartz", "modules\task-management\LINGYUN.Abp.BackgroundTasks.Quartz\LINGYUN.Abp.BackgroundTasks.Quartz.csproj", "{7051C251-11D0-4971-B13E-F6929AE6DE89}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LY.MicroService.TaskManagement.HttpApi.Host", "services\LY.MicroService.TaskManagement.HttpApi.Host\LY.MicroService.TaskManagement.HttpApi.Host.csproj", "{E8022994-A19F-4540-B9D1-7EF4AA85D18A}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LINGYUN.Abp.BackgroundTasks.Abstractions", "modules\task-management\LINGYUN.Abp.BackgroundTasks.Abstractions\LINGYUN.Abp.BackgroundTasks.Abstractions.csproj", "{4A049C32-55F2-4A5F-954A-C8A977C2D87F}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{691CD138-9FFA-4988-BAC4-A32F0DAE1090}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{691CD138-9FFA-4988-BAC4-A32F0DAE1090}.Debug|Any CPU.Build.0 = Debug|Any CPU
{691CD138-9FFA-4988-BAC4-A32F0DAE1090}.Release|Any CPU.ActiveCfg = Release|Any CPU
{691CD138-9FFA-4988-BAC4-A32F0DAE1090}.Release|Any CPU.Build.0 = Release|Any CPU
{8873A651-4F83-43B3-A34E-7AAA8A3ED4CF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{8873A651-4F83-43B3-A34E-7AAA8A3ED4CF}.Debug|Any CPU.Build.0 = Debug|Any CPU
{8873A651-4F83-43B3-A34E-7AAA8A3ED4CF}.Release|Any CPU.ActiveCfg = Release|Any CPU
{8873A651-4F83-43B3-A34E-7AAA8A3ED4CF}.Release|Any CPU.Build.0 = Release|Any CPU
{D5EC4CA0-7E16-4D17-B08E-E162EF332C77}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{D5EC4CA0-7E16-4D17-B08E-E162EF332C77}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D5EC4CA0-7E16-4D17-B08E-E162EF332C77}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D5EC4CA0-7E16-4D17-B08E-E162EF332C77}.Release|Any CPU.Build.0 = Release|Any CPU
{09039DDF-5B0E-4670-8055-CC0BE82D4D2C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{09039DDF-5B0E-4670-8055-CC0BE82D4D2C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{09039DDF-5B0E-4670-8055-CC0BE82D4D2C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{09039DDF-5B0E-4670-8055-CC0BE82D4D2C}.Release|Any CPU.Build.0 = Release|Any CPU
{283B0039-F67C-41F7-B554-DF5EE9178C4A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{283B0039-F67C-41F7-B554-DF5EE9178C4A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{283B0039-F67C-41F7-B554-DF5EE9178C4A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{283B0039-F67C-41F7-B554-DF5EE9178C4A}.Release|Any CPU.Build.0 = Release|Any CPU
{B8AB5E9B-9711-470E-8072-7444579EC5F6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{B8AB5E9B-9711-470E-8072-7444579EC5F6}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B8AB5E9B-9711-470E-8072-7444579EC5F6}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B8AB5E9B-9711-470E-8072-7444579EC5F6}.Release|Any CPU.Build.0 = Release|Any CPU
{AC0B4342-9C9B-41E6-9646-E505C763EE77}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{AC0B4342-9C9B-41E6-9646-E505C763EE77}.Debug|Any CPU.Build.0 = Debug|Any CPU
{AC0B4342-9C9B-41E6-9646-E505C763EE77}.Release|Any CPU.ActiveCfg = Release|Any CPU
{AC0B4342-9C9B-41E6-9646-E505C763EE77}.Release|Any CPU.Build.0 = Release|Any CPU
{7051C251-11D0-4971-B13E-F6929AE6DE89}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{7051C251-11D0-4971-B13E-F6929AE6DE89}.Debug|Any CPU.Build.0 = Debug|Any CPU
{7051C251-11D0-4971-B13E-F6929AE6DE89}.Release|Any CPU.ActiveCfg = Release|Any CPU
{7051C251-11D0-4971-B13E-F6929AE6DE89}.Release|Any CPU.Build.0 = Release|Any CPU
{E8022994-A19F-4540-B9D1-7EF4AA85D18A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{E8022994-A19F-4540-B9D1-7EF4AA85D18A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E8022994-A19F-4540-B9D1-7EF4AA85D18A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E8022994-A19F-4540-B9D1-7EF4AA85D18A}.Release|Any CPU.Build.0 = Release|Any CPU
{4A049C32-55F2-4A5F-954A-C8A977C2D87F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{4A049C32-55F2-4A5F-954A-C8A977C2D87F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{4A049C32-55F2-4A5F-954A-C8A977C2D87F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{4A049C32-55F2-4A5F-954A-C8A977C2D87F}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{691CD138-9FFA-4988-BAC4-A32F0DAE1090} = {C38EB7EF-BAE9-4129-862A-71C652B81775}
{8873A651-4F83-43B3-A34E-7AAA8A3ED4CF} = {C38EB7EF-BAE9-4129-862A-71C652B81775}
{D5EC4CA0-7E16-4D17-B08E-E162EF332C77} = {C38EB7EF-BAE9-4129-862A-71C652B81775}
{09039DDF-5B0E-4670-8055-CC0BE82D4D2C} = {C38EB7EF-BAE9-4129-862A-71C652B81775}
{283B0039-F67C-41F7-B554-DF5EE9178C4A} = {C38EB7EF-BAE9-4129-862A-71C652B81775}
{B8AB5E9B-9711-470E-8072-7444579EC5F6} = {C38EB7EF-BAE9-4129-862A-71C652B81775}
{AC0B4342-9C9B-41E6-9646-E505C763EE77} = {C38EB7EF-BAE9-4129-862A-71C652B81775}
{7051C251-11D0-4971-B13E-F6929AE6DE89} = {385578CC-C0F1-4377-A7A2-682B8F416234}
{E8022994-A19F-4540-B9D1-7EF4AA85D18A} = {8DA8A2EE-0B26-487E-A6C4-518906E92B1B}
{4A049C32-55F2-4A5F-954A-C8A977C2D87F} = {C38EB7EF-BAE9-4129-862A-71C652B81775}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {E1FD1F4C-D344-408B-97CF-B6F1F6D7D293}
EndGlobalSection
EndGlobal

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

@ -0,0 +1,45 @@
using System;
using Volo.Abp;
namespace LINGYUN.Abp.BackgroundTasks;
public class AbpBackgroundTaskConcurrentException : AbpException
{
public Type JobType { get; }
/// <summary>
/// Creates a new <see cref="AbpBackgroundTaskConcurrentException"/> object.
/// </summary>
/// <param name="innerException">Inner exception</param>
public AbpBackgroundTaskConcurrentException(Type jobType)
: this(
jobType,
$"This job {jobType.Name} cannot be performed because it has been locked by another performer",
null)
{
}
/// <summary>
/// Creates a new <see cref="AbpBackgroundTaskConcurrentException"/> object.
/// </summary>
/// <param name="jobType">Execute job type</param>
/// <param name="innerException">Inner exception</param>
public AbpBackgroundTaskConcurrentException(Type jobType, Exception innerException)
: this(
jobType,
$"This job {jobType.Name} cannot be performed because it has been locked by another performer",
innerException)
{
}
/// <summary>
/// Creates a new <see cref="AbpBackgroundTaskConcurrentException"/> object.
/// </summary>
/// <param name="jobType">Execute job type</param>
/// <param name="message">Exception message</param>
/// <param name="innerException">Inner exception</param>
public AbpBackgroundTaskConcurrentException(Type jobType, string message, Exception innerException)
: base(message, innerException)
{
JobType = jobType;
}
}

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

@ -0,0 +1,14 @@
using System;
using Quartz;
namespace LINGYUN.Abp.BackgroundTasks.Quartz;
[DisallowConcurrentExecution]
public class QuartzJobConcurrentAdapter<TJobRunnable> : QuartzJobSimpleAdapter<TJobRunnable>
where TJobRunnable : IJobRunnable
{
public QuartzJobConcurrentAdapter(IServiceProvider serviceProvider)
: base(serviceProvider)
{
}
}

5
aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks.Quartz/LINGYUN/Abp/BackgroundTasks/Quartz/QuartzJobExecutorProvider.cs

@ -35,6 +35,10 @@ public class QuartzJobExecutorProvider : IQuartzJobExecutorProvider, ISingletonD
}
var adapterType = typeof(QuartzJobSimpleAdapter<>);
if (job.LockTimeOut > 0)
{
adapterType = typeof(QuartzJobConcurrentAdapter<>);
}
if (!typeof(IJob).IsAssignableFrom(jobType))
{
@ -88,6 +92,7 @@ public class QuartzJobExecutorProvider : IQuartzJobExecutorProvider, ISingletonD
triggerBuilder
.WithIdentity(job.Name, job.Group)
.WithDescription(job.Description)
.StartAt(Clock.Now.AddSeconds(job.Interval))
.EndAt(job.EndTime)
.ForJob(job.Name, job.Group)
.WithPriority((int)job.Priority)

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

@ -82,7 +82,6 @@ public class QuartzJobListener : JobListenerSupport, ISingletonDependency
}
}
[UnitOfWork]
public override async Task JobWasExecuted(IJobExecutionContext context, JobExecutionException jobException, CancellationToken cancellationToken = default)
{
try
@ -91,9 +90,15 @@ public class QuartzJobListener : JobListenerSupport, ISingletonDependency
var jobId = context.GetString(nameof(JobInfo.Id));
if (Guid.TryParse(jobId, out var jobUUId))
{
var jobType = context.JobDetail.JobType;
if (jobType.IsGenericType)
{
jobType = jobType.GetGenericArguments()[0];
}
var jobEventData = new JobEventData(
jobUUId,
context.JobDetail.JobType,
jobType,
context.JobDetail.Key.Group,
context.JobDetail.Key.Name,
jobException)
@ -112,7 +117,7 @@ public class QuartzJobListener : JobListenerSupport, ISingletonDependency
jobEventData.NextRunTime = context.NextFireTimeUtc?.LocalDateTime;
if (context.Result != null)
{
jobEventData.Result = context.Result.ToString();
jobEventData.Result = context.Result?.ToString();
}
var tenantIdString = context.GetString(nameof(IMultiTenant.TenantId));
if (Guid.TryParse(tenantIdString, out var tenantId))

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

@ -11,7 +11,7 @@
<ItemGroup>
<PackageReference Include="Volo.Abp.Auditing" Version="$(VoloAbpPackageVersion)" />
<PackageReference Include="Volo.Abp.BackgroundJobs.Abstractions" Version="$(VoloAbpPackageVersion)" />
<PackageReference Include="Volo.Abp.DistributedLocking" Version="$(VoloAbpPackageVersion)" />
<PackageReference Include="Volo.Abp.DistributedLocking.Abstractions" Version="$(VoloAbpPackageVersion)" />
<PackageReference Include="Volo.Abp.Guids" Version="$(VoloAbpPackageVersion)" />
</ItemGroup>

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

@ -12,9 +12,9 @@ using Volo.Abp.Reflection;
namespace LINGYUN.Abp.BackgroundTasks;
[DependsOn(typeof(AbpAuditingModule))]
[DependsOn(typeof(AbpDistributedLockingModule))]
[DependsOn(typeof(AbpBackgroundTasksAbstractionsModule))]
[DependsOn(typeof(AbpBackgroundJobsAbstractionsModule))]
[DependsOn(typeof(AbpDistributedLockingAbstractionsModule))]
[DependsOn(typeof(AbpGuidsModule))]
public class AbpBackgroundTasksModule : AbpModule
{

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

@ -1,9 +1,11 @@
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Options;
using System.Threading.Tasks;
using Volo.Abp.Auditing;
namespace LINGYUN.Abp.BackgroundTasks.Internal;
[DisableAuditing]
internal class BackgroundCleaningJob : IJobRunnable
{
public virtual async Task ExecuteAsync(JobRunnableContext context)

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

@ -63,6 +63,7 @@ internal class DefaultBackgroundWorker : BackgroundService
JobType = JobType.Once,
Priority = JobPriority.High,
MaxCount = 1,
Interval = 30,
Type = typeof(BackgroundKeepAliveJob).AssemblyQualifiedName,
};
}

8
aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks/LINGYUN/Abp/BackgroundTasks/Internal/JobExecutedEvent.cs

@ -4,7 +4,7 @@ using Volo.Abp.DependencyInjection;
namespace LINGYUN.Abp.BackgroundTasks.Internal;
internal class JobExecutedEvent : JobEventBase<JobExecutedEvent>, ITransientDependency
public class JobExecutedEvent : JobEventBase<JobExecutedEvent>, ITransientDependency
{
protected override async Task OnJobAfterExecutedAsync(JobEventContext context)
{
@ -15,8 +15,8 @@ internal class JobExecutedEvent : JobEventBase<JobExecutedEvent>, ITransientDepe
{
job.TriggerCount += 1;
job.NextRunTime = context.EventData.NextRunTime;
job.LastRunTime = context.EventData.LastRunTime;
job.Result = context.EventData.Result;
job.LastRunTime = context.EventData.RunTime;
job.Result = context.EventData.Result ?? "OK";
// 一次性任务执行一次后标记为已完成
if (job.JobType == JobType.Once)
@ -53,7 +53,7 @@ internal class JobExecutedEvent : JobEventBase<JobExecutedEvent>, ITransientDepe
}
// 所有任务达到上限则标记已完成
if (job.MaxCount > 0 && job.TriggerCount > job.MaxCount)
if (job.MaxCount > 0 && job.TriggerCount >= job.MaxCount)
{
job.Status = JobStatus.Completed;

3
aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks/LINGYUN/Abp/BackgroundTasks/Internal/JobLogEvent.cs

@ -2,6 +2,7 @@
using System.Threading.Tasks;
using Volo.Abp.Auditing;
using Volo.Abp.DependencyInjection;
using Volo.Abp.Uow;
namespace LINGYUN.Abp.BackgroundTasks.Internal;
@ -11,7 +12,7 @@ namespace LINGYUN.Abp.BackgroundTasks.Internal;
/// <remarks>
/// 任务类型标记了<see cref="DisableAuditingAttribute"/> 特性则不会记录日志
/// </remarks>
internal class JobLogEvent : JobEventBase<JobLogEvent>, ITransientDependency
public class JobLogEvent : JobEventBase<JobLogEvent>, ITransientDependency
{
protected async override Task OnJobAfterExecutedAsync(JobEventContext context)
{

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

@ -10,7 +10,7 @@ namespace LINGYUN.Abp.BackgroundTasks;
public class JobRunnableExecuter : IJobRunnableExecuter, ISingletonDependency
{
protected const string LockKeyFormat = "job:{0},key:{1}";
protected const string LockKeyFormat = "p:{0},job:{1},key:{2}";
public async virtual Task ExecuteAsync(JobRunnableContext context)
{
@ -26,12 +26,21 @@ public class JobRunnableExecuter : IJobRunnableExecuter, ISingletonDependency
{
context.JobData.TryGetValue(nameof(JobInfo.LockTimeOut), out var lockTime);
// 某些提供者如果无法保证锁一致性, 那么需要用分布式锁
if (lockTime != null && (lockTime is int time && time > 0))
{
var jobId = context.JobData.GetOrDefault(nameof(JobInfo.Id));
var jobLockKey = string.Format(LockKeyFormat, context.JobType.Name, jobId);
var jobLockKey = string.Format(LockKeyFormat, tenantId?.ToString() ?? "Default", context.JobType.Name, jobId);
var distributedLock = context.ServiceProvider.GetRequiredService<IAbpDistributedLock>();
await using (await distributedLock.TryAcquireAsync(jobLockKey, TimeSpan.FromSeconds(time)))
var handle = await distributedLock.TryAcquireAsync(jobLockKey, TimeSpan.FromSeconds(time));
if (handle == null)
{
// 抛出异常 通过监听器使其重试
throw new AbpBackgroundTaskConcurrentException(context.JobType);
}
await using (handle)
{
await InternalExecuteAsync(context);
}

16
aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks/LINGYUN/Abp/BackgroundTasks/Primitives/SleepJob.cs

@ -0,0 +1,16 @@
using System;
using System.Threading.Tasks;
namespace LINGYUN.Abp.BackgroundTasks.Primitives;
public class SleepJob : IJobRunnable
{
public async Task ExecuteAsync(JobRunnableContext context)
{
context.JobData.TryGetValue("Delay", out var sleep);
Console.WriteLine($"Sleep {sleep ?? 20000} milliseconds.");
await Task.Delay(sleep?.To<int>() ?? 20000);
}
}

1
aspnet-core/modules/task-management/LINGYUN.Abp.TaskManagement.Application.Contracts/LINGYUN.Abp.TaskManagement.Application.Contracts.csproj

@ -9,6 +9,7 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Volo.Abp.Authorization" Version="$(VoloAbpPackageVersion)" />
<PackageReference Include="Volo.Abp.Ddd.Application.Contracts" Version="$(VoloAbpPackageVersion)" />
</ItemGroup>

1
aspnet-core/modules/task-management/LINGYUN.Abp.TaskManagement.Application.Contracts/LINGYUN/Abp/TaskManagement/BackgroundJobLogGetListInput.cs

@ -5,6 +5,7 @@ namespace LINGYUN.Abp.TaskManagement;
public class BackgroundJobLogGetListInput : PagedAndSortedResultRequestDto
{
public Guid? JobId { get; set; }
/// <summary>
/// 其他过滤条件
/// </summary>

3
aspnet-core/modules/task-management/LINGYUN.Abp.TaskManagement.Application.Contracts/LINGYUN/Abp/TaskManagement/IBackgroundJobLogAppService.cs

@ -6,6 +6,7 @@ public interface IBackgroundJobLogAppService :
IReadOnlyAppService<
BackgroundJobLogDto,
long,
BackgroundJobLogGetListInput>
BackgroundJobLogGetListInput>,
IDeleteAppService<long>
{
}

60
aspnet-core/modules/task-management/LINGYUN.Abp.TaskManagement.Application.Contracts/LINGYUN/Abp/TaskManagement/Permissions/TaskManagementPermissionDefinitionProvider.cs

@ -0,0 +1,60 @@
using LINGYUN.Abp.TaskManagement.Localization;
using Volo.Abp.Authorization.Permissions;
using Volo.Abp.Localization;
using Volo.Abp.MultiTenancy;
namespace LINGYUN.Abp.TaskManagement.Permissions;
public class TaskManagementPermissionDefinitionProvider : PermissionDefinitionProvider
{
public override void Define(IPermissionDefinitionContext context)
{
var group = context.AddGroup(
TaskManagementPermissions.GroupName,
L("Permissions:TaskManagement"),
MultiTenancySides.Host);
var backgroundJobs = group.AddPermission(
TaskManagementPermissions.BackgroundJobs.Default,
L("Permissions:BackgroundJobs"),
MultiTenancySides.Host);
backgroundJobs.AddChild(
TaskManagementPermissions.BackgroundJobs.Create,
L("Permissions:CreateJob"),
MultiTenancySides.Host);
backgroundJobs.AddChild(
TaskManagementPermissions.BackgroundJobs.Update,
L("Permissions:UpdateJob"),
MultiTenancySides.Host);
backgroundJobs.AddChild(
TaskManagementPermissions.BackgroundJobs.Delete,
L("Permissions:DeleteJob"),
MultiTenancySides.Host);
backgroundJobs.AddChild(
TaskManagementPermissions.BackgroundJobs.Trigger,
L("Permissions:TriggerJob"),
MultiTenancySides.Host);
backgroundJobs.AddChild(
TaskManagementPermissions.BackgroundJobs.Pause,
L("Permissions:PauseJob"),
MultiTenancySides.Host);
backgroundJobs.AddChild(
TaskManagementPermissions.BackgroundJobs.Resume,
L("Permissions:ResumeJob"),
MultiTenancySides.Host);
var backgroundJobLogs = group.AddPermission(
TaskManagementPermissions.BackgroundJobLogs.Default,
L("Permissions:BackgroundJobLogs"),
MultiTenancySides.Host);
backgroundJobLogs.AddChild(
TaskManagementPermissions.BackgroundJobLogs.Delete,
L("Permissions:DeleteJobLogs"),
MultiTenancySides.Host);
}
private ILocalizableString L(string name)
{
return LocalizableString.Create<TaskManagementResource>(name);
}
}

6
aspnet-core/modules/task-management/LINGYUN.Abp.TaskManagement.Application.Contracts/LINGYUN/Abp/TaskManagement/Permissions/TaskManagementPermissions.cs

@ -14,4 +14,10 @@ public static class TaskManagementPermissions
public const string Pause = Default + ".Pause";
public const string Resume = Default + ".Resume";
}
public static class BackgroundJobLogs
{
public const string Default = GroupName + ".BackgroundJobLogs";
public const string Delete = Default + ".Delete";
}
}

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

@ -0,0 +1,8 @@
namespace LINGYUN.Abp.TaskManagement;
public static class TaskManagementRemoteServiceConsts
{
public const string RemoteServiceName = "TaskManagement";
public const string ModuleName = "task-management";
}

53
aspnet-core/modules/task-management/LINGYUN.Abp.TaskManagement.Application/LINGYUN/Abp/TaskManagement/BackgroundJobLogAppService.cs

@ -0,0 +1,53 @@
using LINGYUN.Abp.TaskManagement.Permissions;
using Microsoft.AspNetCore.Authorization;
using System.Collections.Generic;
using System.Threading.Tasks;
using Volo.Abp.Application.Dtos;
namespace LINGYUN.Abp.TaskManagement;
[Authorize(TaskManagementPermissions.BackgroundJobLogs.Default)]
public class BackgroundJobLogAppService : TaskManagementApplicationService, IBackgroundJobLogAppService
{
protected IBackgroundJobLogRepository BackgroundJobLogRepository { get; }
public BackgroundJobLogAppService(
IBackgroundJobLogRepository backgroundJobLogRepository)
{
BackgroundJobLogRepository = backgroundJobLogRepository;
}
[Authorize(TaskManagementPermissions.BackgroundJobLogs.Delete)]
public virtual Task DeleteAsync(long id)
{
return BackgroundJobLogRepository.DeleteAsync(id);
}
public virtual async Task<BackgroundJobLogDto> GetAsync(long id)
{
var backgroundJobLog = await BackgroundJobLogRepository.GetAsync(id);
return ObjectMapper.Map<BackgroundJobLog, BackgroundJobLogDto>(backgroundJobLog);
}
public virtual async Task<PagedResultDto<BackgroundJobLogDto>> GetListAsync(BackgroundJobLogGetListInput input)
{
var filter = new BackgroundJobLogFilter
{
BeginRunTime = input.BeginRunTime,
EndRunTime = input.EndRunTime,
HasExceptions = input.HasExceptions,
Filter = input.Filter,
Group = input.Group,
Name = input.Name,
Type = input.Type
};
var totalCount = await BackgroundJobLogRepository.GetCountAsync(filter, input.JobId);
var backgroundJobLogs = await BackgroundJobLogRepository.GetListAsync(
filter, input.JobId, input.Sorting, input.MaxResultCount, input.SkipCount);
return new PagedResultDto<BackgroundJobLogDto>(totalCount,
ObjectMapper.Map<List<BackgroundJobLog>, List<BackgroundJobLogDto>>(backgroundJobLogs));
}
}

1
aspnet-core/modules/task-management/LINGYUN.Abp.TaskManagement.Application/LINGYUN/Abp/TaskManagement/TaskManagementApplicationMapperProfile.cs

@ -7,5 +7,6 @@ public class TaskManagementApplicationMapperProfile : Profile
public TaskManagementApplicationMapperProfile()
{
CreateMap<BackgroundJobInfo, BackgroundJobInfoDto>();
CreateMap<BackgroundJobLog, BackgroundJobLogDto>();
}
}

1
aspnet-core/modules/task-management/LINGYUN.Abp.TaskManagement.Domain.Shared/LINGYUN/Abp/TaskManagement/BackgroundJobInfoConsts.cs

@ -7,4 +7,5 @@ public static class BackgroundJobInfoConsts
public static int MaxGroupLength { get; set; } = 50;
public static int MaxTypeLength { get; set; } = 200;
public static int MaxDescriptionLength { get; set; } = 255;
public static int MaxResultLength { get; set; } = 1000;
}

12
aspnet-core/modules/task-management/LINGYUN.Abp.TaskManagement.Domain.Shared/LINGYUN/Abp/TaskManagement/Localization/Resources/en.json

@ -1,6 +1,16 @@
{
"culture": "en",
"texts": {
"Permission:TaskManagement": "TaskManagement"
"Permissions:TaskManagement": "Task Management",
"Permissions:BackgroundJobs": "Background Jobs",
"Permissions:CreateJob": "Create Job",
"Permissions:UpdateJob": "Update Job",
"Permissions:DeleteJob": "Delete Job",
"Permissions:TriggerJob": "Trigger Job",
"Permissions:PauseJob": "Pause Job",
"Permissions:ResumeJob": "Resume Job",
"Permissions:BackgroundJobLogs": "BackgroundJobs Logs",
"Permissions:DeleteJobLogs": "Delete Job Logs",
"TaskManagement:01000": "A job named {Name} already exists in the Group {Group}!"
}
}

12
aspnet-core/modules/task-management/LINGYUN.Abp.TaskManagement.Domain.Shared/LINGYUN/Abp/TaskManagement/Localization/Resources/zh-Hans.json

@ -1,6 +1,16 @@
{
"culture": "zh-Hans",
"texts": {
"Permission:TaskManagement": "任务管理"
"Permissions:TaskManagement": "任务调度平台",
"Permissions:BackgroundJobs": "任务管理",
"Permissions:CreateJob": "新建作业",
"Permissions:UpdateJob": "编辑作业",
"Permissions:DeleteJob": "删除作业",
"Permissions:TriggerJob": "触发作业",
"Permissions:PauseJob": "暂停作业",
"Permissions:ResumeJob": "恢复作业",
"Permissions:BackgroundJobLogs": "日志管理",
"Permissions:DeleteJobLogs": "删除作业日志",
"TaskManagement:01000": "分组 {Group} 中已经存在一个名称为 {Name} 的作业!"
}
}

29
aspnet-core/modules/task-management/LINGYUN.Abp.TaskManagement.Domain/LINGYUN/Abp/TaskManagement/BackgroundJobInfo.cs

@ -1,6 +1,7 @@
using LINGYUN.Abp.BackgroundTasks;
using System;
using System.Collections.Generic;
using Volo.Abp;
using Volo.Abp.Data;
using Volo.Abp.Domain.Entities.Auditing;
@ -21,6 +22,10 @@ public class BackgroundJobInfo : AuditedAggregateRoot<Guid>
/// </summary>
public virtual string Type { get; protected set; }
/// <summary>
/// 上一次执行结果
/// </summary>
public virtual string Result { get; protected set; }
/// <summary>
/// 任务参数
/// </summary>
public virtual ExtraPropertyDictionary Args { get; protected set; }
@ -111,9 +116,9 @@ public class BackgroundJobInfo : AuditedAggregateRoot<Guid>
int maxCount = 0,
int maxTryCount = 50) : base(id)
{
Name = name;
Group = group;
Type = type;
Name = Check.NotNullOrWhiteSpace(name, nameof(name), BackgroundJobInfoConsts.MaxNameLength);
Group = Check.NotNullOrWhiteSpace(group, nameof(group), BackgroundJobInfoConsts.MaxGroupLength);
Type = Check.NotNullOrWhiteSpace(type, nameof(type), BackgroundJobInfoConsts.MaxTypeLength);
Priority = priority;
BeginTime = beginTime;
EndTime = endTime;
@ -123,13 +128,15 @@ public class BackgroundJobInfo : AuditedAggregateRoot<Guid>
Status = JobStatus.Running;
// TODO: 是否需要将参数挪到另一个实体?
// 任务参数的建议是尽量最小化, 仅存储关键信息
Args = new ExtraPropertyDictionary();
Args.AddIfNotContains(args);
}
public void SetPeriodJob(string cron)
{
Cron = cron;
Cron = Check.NotNullOrWhiteSpace(cron, nameof(cron), BackgroundJobInfoConsts.MaxCronLength);
JobType = JobType.Period;
}
@ -155,6 +162,20 @@ public class BackgroundJobInfo : AuditedAggregateRoot<Guid>
NextRunTime = nextRunTime;
}
public void SetResult(string result)
{
if (result.IsNullOrWhiteSpace())
{
return;
}
if (result.Length > BackgroundJobInfoConsts.MaxResultLength)
{
result = result.Substring(0, BackgroundJobInfoConsts.MaxResultLength - 1);
}
Result = result;
}
public void SetStatus(JobStatus status)
{
Status = status;

15
aspnet-core/modules/task-management/LINGYUN.Abp.TaskManagement.Domain/LINGYUN/Abp/TaskManagement/BackgroundJobLog.cs

@ -1,4 +1,5 @@
using System;
using Volo.Abp;
using Volo.Abp.Domain.Entities;
namespace LINGYUN.Abp.TaskManagement;
@ -13,12 +14,16 @@ public class BackgroundJobLog : Entity<long>
public virtual DateTime RunTime { get; protected set; }
public virtual string Exception { get; protected set; }
protected BackgroundJobLog() { }
public BackgroundJobLog(string type, string group, string name)
public BackgroundJobLog(
string type,
string group,
string name,
DateTime runTime)
{
JobType = type;
JobGroup = group;
JobName = name;
RunTime = DateTime.Now;
JobType = Check.NotNullOrWhiteSpace(type, nameof(type), BackgroundJobInfoConsts.MaxTypeLength);
JobGroup = Check.NotNullOrWhiteSpace(group, nameof(group), BackgroundJobInfoConsts.MaxGroupLength);
JobName = Check.NotNullOrWhiteSpace(name, nameof(name), BackgroundJobInfoConsts.MaxNameLength);
RunTime = runTime;
}
public BackgroundJobLog SetMessage(string message, Exception ex)

37
aspnet-core/modules/task-management/LINGYUN.Abp.TaskManagement.Domain/LINGYUN/Abp/TaskManagement/BackgroundJobManager.cs

@ -1,7 +1,9 @@
using LINGYUN.Abp.BackgroundTasks;
using System.Threading.Tasks;
using Volo.Abp;
using Volo.Abp.Domain.Services;
using Volo.Abp.ObjectMapping;
using Volo.Abp.Uow;
namespace LINGYUN.Abp.TaskManagement;
@ -9,15 +11,18 @@ public class BackgroundJobManager : DomainService
{
protected IObjectMapper ObjectMapper { get; }
protected IJobScheduler JobScheduler { get; }
protected IUnitOfWorkManager UnitOfWorkManager { get; }
protected IBackgroundJobInfoRepository BackgroundJobInfoRepository { get; }
public BackgroundJobManager(
IObjectMapper objectMapper,
IJobScheduler jobScheduler,
IUnitOfWorkManager unitOfWorkManager,
IBackgroundJobInfoRepository backgroundJobInfoRepository)
{
ObjectMapper = objectMapper;
JobScheduler = jobScheduler;
UnitOfWorkManager = unitOfWorkManager;
BackgroundJobInfoRepository = backgroundJobInfoRepository;
}
@ -28,7 +33,16 @@ public class BackgroundJobManager : DomainService
if (jobInfo.IsEnabled && jobInfo.JobType == JobType.Period)
{
var job = ObjectMapper.Map<BackgroundJobInfo, JobInfo>(jobInfo);
await JobScheduler.QueueAsync(job);
if (await JobScheduler.ExistsAsync(job))
{
throw new BusinessException(TaskManagementErrorCodes.JobNameAlreadyExists)
.WithData("Group", job.Group)
.WithData("Name", job.Name);
}
UnitOfWorkManager.Current.OnCompleted(async () =>
{
await JobScheduler.QueueAsync(job);
});
}
return jobInfo;
@ -40,13 +54,19 @@ public class BackgroundJobManager : DomainService
if (!jobInfo.IsEnabled || resetJob)
{
var job = ObjectMapper.Map<BackgroundJobInfo, JobInfo>(jobInfo);
await JobScheduler.RemoveAsync(job);
UnitOfWorkManager.Current.OnCompleted(async () =>
{
var job = ObjectMapper.Map<BackgroundJobInfo, JobInfo>(jobInfo);
await JobScheduler.RemoveAsync(job);
});
}
if (resetJob && jobInfo.JobType == JobType.Period)
{
await QueueAsync(jobInfo);
UnitOfWorkManager.Current.OnCompleted(async () =>
{
await QueueAsync(jobInfo);
});
}
return jobInfo;
@ -54,10 +74,13 @@ public class BackgroundJobManager : DomainService
public virtual async Task DeleteAsync(BackgroundJobInfo jobInfo)
{
var job = ObjectMapper.Map<BackgroundJobInfo, JobInfo>(jobInfo);
await JobScheduler.RemoveAsync(job);
await BackgroundJobInfoRepository.DeleteAsync(jobInfo);
UnitOfWorkManager.Current.OnCompleted(async () =>
{
var job = ObjectMapper.Map<BackgroundJobInfo, JobInfo>(jobInfo);
await JobScheduler.RemoveAsync(job);
});
}
public virtual async Task QueueAsync(BackgroundJobInfo jobInfo)

5
aspnet-core/modules/task-management/LINGYUN.Abp.TaskManagement.Domain/LINGYUN/Abp/TaskManagement/BackgroundJobStore.cs

@ -56,6 +56,7 @@ public class BackgroundJobStore : IJobStore, ITransientDependency
backgroundJobInfo.SetNextRunTime(jobInfo.NextRunTime);
backgroundJobInfo.SetLastRunTime(jobInfo.LastRunTime);
backgroundJobInfo.SetStatus(jobInfo.Status);
backgroundJobInfo.SetResult(jobInfo.Result);
backgroundJobInfo.TriggerCount = jobInfo.TriggerCount;
backgroundJobInfo.TryCount = jobInfo.TryCount;
backgroundJobInfo.IsAbandoned = jobInfo.IsAbandoned;
@ -79,6 +80,7 @@ public class BackgroundJobStore : IJobStore, ITransientDependency
backgroundJobInfo.SetNextRunTime(jobInfo.NextRunTime);
backgroundJobInfo.SetLastRunTime(jobInfo.LastRunTime);
backgroundJobInfo.SetStatus(jobInfo.Status);
backgroundJobInfo.SetResult(jobInfo.Result);
backgroundJobInfo.TriggerCount = jobInfo.TriggerCount;
backgroundJobInfo.IsAbandoned = jobInfo.IsAbandoned;
backgroundJobInfo.TryCount = jobInfo.TryCount;
@ -107,7 +109,8 @@ public class BackgroundJobStore : IJobStore, ITransientDependency
var jogLog = new BackgroundJobLog(
eventData.Type.Name,
eventData.Group,
eventData.Name)
eventData.Name,
eventData.RunTime)
{
JobId = eventData.Key
};

2
aspnet-core/modules/task-management/LINGYUN.Abp.TaskManagement.EntityFrameworkCore/LINGYUN/Abp/TaskManagement/EntityFrameworkCore/EfCoreBackgroundJobInfoRepository.cs

@ -32,7 +32,7 @@ public class EfCoreBackgroundJobInfoRepository :
CancellationToken cancellationToken = default)
{
return await (await GetDbSetAsync())
.AllAsync(x => x.Group.Equals(group) && x.Name.Equals(name),
.AnyAsync(x => x.Group.Equals(group) && x.Name.Equals(name),
GetCancellationToken(cancellationToken));
}

3
aspnet-core/modules/task-management/LINGYUN.Abp.TaskManagement.EntityFrameworkCore/LINGYUN/Abp/TaskManagement/EntityFrameworkCore/TaskManagementDbContextModelCreatingExtensions.cs

@ -43,6 +43,9 @@ public static class TaskManagementDbContextModelCreatingExtensions
b.Property(p => p.Description)
.HasColumnName(nameof(BackgroundJobInfo.Description))
.HasMaxLength(BackgroundJobInfoConsts.MaxDescriptionLength);
b.Property(p => p.Result)
.HasColumnName(nameof(BackgroundJobInfo.Result))
.HasMaxLength(BackgroundJobInfoConsts.MaxResultLength);
b.Property(p => p.Args)
.HasColumnName(nameof(BackgroundJobInfo.Args))
.HasConversion(new ExtraPropertiesValueConverter(b.Metadata.ClrType))

84
aspnet-core/modules/task-management/LINGYUN.Abp.TaskManagement.HttpApi/LINGYUN/Abp/TaskManagement/BackgroundJobInfoController.cs

@ -0,0 +1,84 @@
using LINGYUN.Abp.TaskManagement.Permissions;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Threading.Tasks;
using Volo.Abp;
using Volo.Abp.Application.Dtos;
namespace LINGYUN.Abp.TaskManagement;
[RemoteService(Name = TaskManagementRemoteServiceConsts.RemoteServiceName)]
[Area(TaskManagementRemoteServiceConsts.ModuleName)]
[Authorize(TaskManagementPermissions.BackgroundJobs.Default)]
[Route($"api/{TaskManagementRemoteServiceConsts.ModuleName}/background-jobs")]
public class BackgroundJobInfoController : TaskManagementController, IBackgroundJobInfoAppService
{
protected IBackgroundJobInfoAppService BackgroundJobInfoAppService { get; }
public BackgroundJobInfoController(
IBackgroundJobInfoAppService backgroundJobInfoAppService)
{
BackgroundJobInfoAppService = backgroundJobInfoAppService;
}
[HttpPost]
[Authorize(TaskManagementPermissions.BackgroundJobs.Create)]
public Task<BackgroundJobInfoDto> CreateAsync(BackgroundJobInfoCreateDto input)
{
return BackgroundJobInfoAppService.CreateAsync(input);
}
[HttpDelete]
[Route("{id}")]
[Authorize(TaskManagementPermissions.BackgroundJobs.Delete)]
public Task DeleteAsync(Guid id)
{
return BackgroundJobInfoAppService.DeleteAsync(id);
}
[HttpGet]
[Route("{id}")]
public Task<BackgroundJobInfoDto> GetAsync(Guid id)
{
return BackgroundJobInfoAppService.GetAsync(id);
}
[HttpGet]
public Task<PagedResultDto<BackgroundJobInfoDto>> GetListAsync(BackgroundJobInfoGetListInput input)
{
return BackgroundJobInfoAppService.GetListAsync(input);
}
[HttpPut]
[Route("{id}/pause")]
[Authorize(TaskManagementPermissions.BackgroundJobs.Pause)]
public Task PauseAsync(Guid id)
{
return BackgroundJobInfoAppService.PauseAsync(id);
}
[HttpPut]
[Route("{id}/resume")]
[Authorize(TaskManagementPermissions.BackgroundJobs.Resume)]
public Task ResumeAsync(Guid id)
{
return BackgroundJobInfoAppService.ResumeAsync(id);
}
[HttpPut]
[Route("{id}/trigger")]
[Authorize(TaskManagementPermissions.BackgroundJobs.Trigger)]
public Task TriggerAsync(Guid id)
{
return BackgroundJobInfoAppService.TriggerAsync(id);
}
[HttpPut]
[Route("{id}")]
[Authorize(TaskManagementPermissions.BackgroundJobs.Update)]
public Task<BackgroundJobInfoDto> UpdateAsync(Guid id, BackgroundJobInfoUpdateDto input)
{
return BackgroundJobInfoAppService.UpdateAsync(id, input);
}
}

44
aspnet-core/modules/task-management/LINGYUN.Abp.TaskManagement.HttpApi/LINGYUN/Abp/TaskManagement/BackgroundJobLogController.cs

@ -0,0 +1,44 @@
using LINGYUN.Abp.TaskManagement.Permissions;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using System.Threading.Tasks;
using Volo.Abp;
using Volo.Abp.Application.Dtos;
namespace LINGYUN.Abp.TaskManagement;
[RemoteService(Name = TaskManagementRemoteServiceConsts.RemoteServiceName)]
[Area(TaskManagementRemoteServiceConsts.ModuleName)]
[Authorize(TaskManagementPermissions.BackgroundJobLogs.Default)]
[Route($"api/{TaskManagementRemoteServiceConsts.ModuleName}/background-jobs/logs")]
public class BackgroundJobLogController : TaskManagementController, IBackgroundJobLogAppService
{
protected IBackgroundJobLogAppService BackgroundJobLogAppService { get; }
public BackgroundJobLogController(
IBackgroundJobLogAppService backgroundJobLogAppService)
{
BackgroundJobLogAppService = backgroundJobLogAppService;
}
[HttpDelete]
[Route("{id}")]
[Authorize(TaskManagementPermissions.BackgroundJobLogs.Delete)]
public Task DeleteAsync(long id)
{
return BackgroundJobLogAppService.DeleteAsync(id);
}
[HttpGet]
[Route("{id}")]
public Task<BackgroundJobLogDto> GetAsync(long id)
{
return BackgroundJobLogAppService.GetAsync(id);
}
[HttpGet]
public Task<PagedResultDto<BackgroundJobLogDto>> GetListAsync(BackgroundJobLogGetListInput input)
{
return BackgroundJobLogAppService.GetListAsync(input);
}
}

12
aspnet-core/modules/task-management/LINGYUN.Abp.TaskManagement.HttpApi/LINGYUN/Abp/TaskManagement/TaskManagementController.cs

@ -0,0 +1,12 @@
using LINGYUN.Abp.TaskManagement.Localization;
using Volo.Abp.AspNetCore.Mvc;
namespace LINGYUN.Abp.TaskManagement;
public abstract class TaskManagementController : AbpControllerBase
{
protected TaskManagementController()
{
LocalizationResource = typeof(TaskManagementResource);
}
}

188
aspnet-core/services/LY.MicroService.TaskManagement.HttpApi.Host/Migrations/20220109030916_Add-Module-Task-Management.Designer.cs

@ -0,0 +1,188 @@
// <auto-generated />
using System;
using LY.MicroService.TaskManagement.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using Volo.Abp.EntityFrameworkCore;
#nullable disable
namespace LY.MicroService.TaskManagement.Migrations
{
[DbContext(typeof(TaskManagementMigrationsDbContext))]
[Migration("20220109030916_Add-Module-Task-Management")]
partial class AddModuleTaskManagement
{
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("_Abp_DatabaseProvider", EfCoreDatabaseProvider.MySql)
.HasAnnotation("ProductVersion", "6.0.1")
.HasAnnotation("Relational:MaxIdentifierLength", 64);
modelBuilder.Entity("LINGYUN.Abp.TaskManagement.BackgroundJobInfo", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("char(36)");
b.Property<string>("Args")
.HasColumnType("longtext")
.HasColumnName("Args");
b.Property<DateTime>("BeginTime")
.HasColumnType("datetime(6)");
b.Property<string>("ConcurrencyStamp")
.IsConcurrencyToken()
.HasMaxLength(40)
.HasColumnType("varchar(40)")
.HasColumnName("ConcurrencyStamp");
b.Property<DateTime>("CreationTime")
.HasColumnType("datetime(6)")
.HasColumnName("CreationTime");
b.Property<Guid?>("CreatorId")
.HasColumnType("char(36)")
.HasColumnName("CreatorId");
b.Property<string>("Cron")
.HasMaxLength(50)
.HasColumnType("varchar(50)")
.HasColumnName("Cron");
b.Property<string>("Description")
.HasMaxLength(255)
.HasColumnType("varchar(255)")
.HasColumnName("Description");
b.Property<DateTime?>("EndTime")
.HasColumnType("datetime(6)");
b.Property<string>("ExtraProperties")
.HasColumnType("longtext")
.HasColumnName("ExtraProperties");
b.Property<string>("Group")
.IsRequired()
.HasMaxLength(50)
.HasColumnType("varchar(50)")
.HasColumnName("Group");
b.Property<int>("Interval")
.HasColumnType("int");
b.Property<bool>("IsAbandoned")
.HasColumnType("tinyint(1)");
b.Property<bool>("IsEnabled")
.HasColumnType("tinyint(1)");
b.Property<int>("JobType")
.HasColumnType("int");
b.Property<DateTime?>("LastModificationTime")
.HasColumnType("datetime(6)")
.HasColumnName("LastModificationTime");
b.Property<Guid?>("LastModifierId")
.HasColumnType("char(36)")
.HasColumnName("LastModifierId");
b.Property<DateTime?>("LastRunTime")
.HasColumnType("datetime(6)");
b.Property<int>("LockTimeOut")
.HasColumnType("int");
b.Property<int>("MaxCount")
.HasColumnType("int");
b.Property<int>("MaxTryCount")
.HasColumnType("int");
b.Property<string>("Name")
.IsRequired()
.HasMaxLength(100)
.HasColumnType("varchar(100)")
.HasColumnName("Name");
b.Property<DateTime?>("NextRunTime")
.HasColumnType("datetime(6)");
b.Property<int>("Priority")
.HasColumnType("int");
b.Property<int>("Status")
.HasColumnType("int");
b.Property<int>("TriggerCount")
.HasColumnType("int");
b.Property<int>("TryCount")
.HasColumnType("int");
b.Property<string>("Type")
.IsRequired()
.HasMaxLength(200)
.HasColumnType("varchar(200)")
.HasColumnName("Type");
b.HasKey("Id");
b.HasIndex("Name", "Group");
b.ToTable("TK_BackgroundJobs", (string)null);
});
modelBuilder.Entity("LINGYUN.Abp.TaskManagement.BackgroundJobLog", b =>
{
b.Property<long>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("bigint");
b.Property<string>("Exception")
.HasMaxLength(2000)
.HasColumnType("varchar(2000)")
.HasColumnName("Exception");
b.Property<string>("JobGroup")
.HasMaxLength(50)
.HasColumnType("varchar(50)")
.HasColumnName("JobGroup");
b.Property<Guid?>("JobId")
.HasColumnType("char(36)");
b.Property<string>("JobName")
.HasMaxLength(100)
.HasColumnType("varchar(100)")
.HasColumnName("JobName");
b.Property<string>("JobType")
.HasMaxLength(200)
.HasColumnType("varchar(200)")
.HasColumnName("JobType");
b.Property<string>("Message")
.HasMaxLength(1000)
.HasColumnType("varchar(1000)")
.HasColumnName("Message");
b.Property<DateTime>("RunTime")
.HasColumnType("datetime(6)");
b.HasKey("Id");
b.HasIndex("JobGroup", "JobName");
b.ToTable("TK_BackgroundJobLogs", (string)null);
});
#pragma warning restore 612, 618
}
}
}

108
aspnet-core/services/LY.MicroService.TaskManagement.HttpApi.Host/Migrations/20220109030916_Add-Module-Task-Management.cs

@ -0,0 +1,108 @@
using System;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace LY.MicroService.TaskManagement.Migrations
{
public partial class AddModuleTaskManagement : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AlterDatabase()
.Annotation("MySql:CharSet", "utf8mb4");
migrationBuilder.CreateTable(
name: "TK_BackgroundJobLogs",
columns: table => new
{
Id = table.Column<long>(type: "bigint", nullable: false)
.Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
JobId = table.Column<Guid>(type: "char(36)", nullable: true, collation: "ascii_general_ci"),
JobName = table.Column<string>(type: "varchar(100)", maxLength: 100, nullable: true)
.Annotation("MySql:CharSet", "utf8mb4"),
JobGroup = table.Column<string>(type: "varchar(50)", maxLength: 50, nullable: true)
.Annotation("MySql:CharSet", "utf8mb4"),
JobType = table.Column<string>(type: "varchar(200)", maxLength: 200, nullable: true)
.Annotation("MySql:CharSet", "utf8mb4"),
Message = table.Column<string>(type: "varchar(1000)", maxLength: 1000, nullable: true)
.Annotation("MySql:CharSet", "utf8mb4"),
RunTime = table.Column<DateTime>(type: "datetime(6)", nullable: false),
Exception = table.Column<string>(type: "varchar(2000)", maxLength: 2000, nullable: true)
.Annotation("MySql:CharSet", "utf8mb4")
},
constraints: table =>
{
table.PrimaryKey("PK_TK_BackgroundJobLogs", x => x.Id);
})
.Annotation("MySql:CharSet", "utf8mb4");
migrationBuilder.CreateTable(
name: "TK_BackgroundJobs",
columns: table => new
{
Id = table.Column<Guid>(type: "char(36)", nullable: false, collation: "ascii_general_ci"),
Name = table.Column<string>(type: "varchar(100)", maxLength: 100, nullable: false)
.Annotation("MySql:CharSet", "utf8mb4"),
Group = table.Column<string>(type: "varchar(50)", maxLength: 50, nullable: false)
.Annotation("MySql:CharSet", "utf8mb4"),
Type = table.Column<string>(type: "varchar(200)", maxLength: 200, nullable: false)
.Annotation("MySql:CharSet", "utf8mb4"),
Args = table.Column<string>(type: "longtext", nullable: true)
.Annotation("MySql:CharSet", "utf8mb4"),
Status = table.Column<int>(type: "int", nullable: false),
IsEnabled = table.Column<bool>(type: "tinyint(1)", nullable: false),
Description = table.Column<string>(type: "varchar(255)", maxLength: 255, nullable: true)
.Annotation("MySql:CharSet", "utf8mb4"),
LockTimeOut = table.Column<int>(type: "int", nullable: false),
BeginTime = table.Column<DateTime>(type: "datetime(6)", nullable: false),
EndTime = table.Column<DateTime>(type: "datetime(6)", nullable: true),
LastRunTime = table.Column<DateTime>(type: "datetime(6)", nullable: true),
NextRunTime = table.Column<DateTime>(type: "datetime(6)", nullable: true),
JobType = table.Column<int>(type: "int", nullable: false),
Cron = table.Column<string>(type: "varchar(50)", maxLength: 50, nullable: true)
.Annotation("MySql:CharSet", "utf8mb4"),
Priority = table.Column<int>(type: "int", nullable: false),
TriggerCount = table.Column<int>(type: "int", nullable: false),
TryCount = table.Column<int>(type: "int", nullable: false),
MaxTryCount = table.Column<int>(type: "int", nullable: false),
MaxCount = table.Column<int>(type: "int", nullable: false),
Interval = table.Column<int>(type: "int", nullable: false),
IsAbandoned = table.Column<bool>(type: "tinyint(1)", nullable: false),
ExtraProperties = table.Column<string>(type: "longtext", nullable: true)
.Annotation("MySql:CharSet", "utf8mb4"),
ConcurrencyStamp = table.Column<string>(type: "varchar(40)", maxLength: 40, nullable: true)
.Annotation("MySql:CharSet", "utf8mb4"),
CreationTime = table.Column<DateTime>(type: "datetime(6)", nullable: false),
CreatorId = table.Column<Guid>(type: "char(36)", nullable: true, collation: "ascii_general_ci"),
LastModificationTime = table.Column<DateTime>(type: "datetime(6)", nullable: true),
LastModifierId = table.Column<Guid>(type: "char(36)", nullable: true, collation: "ascii_general_ci")
},
constraints: table =>
{
table.PrimaryKey("PK_TK_BackgroundJobs", x => x.Id);
})
.Annotation("MySql:CharSet", "utf8mb4");
migrationBuilder.CreateIndex(
name: "IX_TK_BackgroundJobLogs_JobGroup_JobName",
table: "TK_BackgroundJobLogs",
columns: new[] { "JobGroup", "JobName" });
migrationBuilder.CreateIndex(
name: "IX_TK_BackgroundJobs_Name_Group",
table: "TK_BackgroundJobs",
columns: new[] { "Name", "Group" });
}
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "TK_BackgroundJobLogs");
migrationBuilder.DropTable(
name: "TK_BackgroundJobs");
}
}
}

193
aspnet-core/services/LY.MicroService.TaskManagement.HttpApi.Host/Migrations/20220109033926_Add-Field-Result-With-Background-Job-Info.Designer.cs

@ -0,0 +1,193 @@
// <auto-generated />
using System;
using LY.MicroService.TaskManagement.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using Volo.Abp.EntityFrameworkCore;
#nullable disable
namespace LY.MicroService.TaskManagement.Migrations
{
[DbContext(typeof(TaskManagementMigrationsDbContext))]
[Migration("20220109033926_Add-Field-Result-With-Background-Job-Info")]
partial class AddFieldResultWithBackgroundJobInfo
{
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("_Abp_DatabaseProvider", EfCoreDatabaseProvider.MySql)
.HasAnnotation("ProductVersion", "6.0.1")
.HasAnnotation("Relational:MaxIdentifierLength", 64);
modelBuilder.Entity("LINGYUN.Abp.TaskManagement.BackgroundJobInfo", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("char(36)");
b.Property<string>("Args")
.HasColumnType("longtext")
.HasColumnName("Args");
b.Property<DateTime>("BeginTime")
.HasColumnType("datetime(6)");
b.Property<string>("ConcurrencyStamp")
.IsConcurrencyToken()
.HasMaxLength(40)
.HasColumnType("varchar(40)")
.HasColumnName("ConcurrencyStamp");
b.Property<DateTime>("CreationTime")
.HasColumnType("datetime(6)")
.HasColumnName("CreationTime");
b.Property<Guid?>("CreatorId")
.HasColumnType("char(36)")
.HasColumnName("CreatorId");
b.Property<string>("Cron")
.HasMaxLength(50)
.HasColumnType("varchar(50)")
.HasColumnName("Cron");
b.Property<string>("Description")
.HasMaxLength(255)
.HasColumnType("varchar(255)")
.HasColumnName("Description");
b.Property<DateTime?>("EndTime")
.HasColumnType("datetime(6)");
b.Property<string>("ExtraProperties")
.HasColumnType("longtext")
.HasColumnName("ExtraProperties");
b.Property<string>("Group")
.IsRequired()
.HasMaxLength(50)
.HasColumnType("varchar(50)")
.HasColumnName("Group");
b.Property<int>("Interval")
.HasColumnType("int");
b.Property<bool>("IsAbandoned")
.HasColumnType("tinyint(1)");
b.Property<bool>("IsEnabled")
.HasColumnType("tinyint(1)");
b.Property<int>("JobType")
.HasColumnType("int");
b.Property<DateTime?>("LastModificationTime")
.HasColumnType("datetime(6)")
.HasColumnName("LastModificationTime");
b.Property<Guid?>("LastModifierId")
.HasColumnType("char(36)")
.HasColumnName("LastModifierId");
b.Property<DateTime?>("LastRunTime")
.HasColumnType("datetime(6)");
b.Property<int>("LockTimeOut")
.HasColumnType("int");
b.Property<int>("MaxCount")
.HasColumnType("int");
b.Property<int>("MaxTryCount")
.HasColumnType("int");
b.Property<string>("Name")
.IsRequired()
.HasMaxLength(100)
.HasColumnType("varchar(100)")
.HasColumnName("Name");
b.Property<DateTime?>("NextRunTime")
.HasColumnType("datetime(6)");
b.Property<int>("Priority")
.HasColumnType("int");
b.Property<string>("Result")
.HasMaxLength(1000)
.HasColumnType("varchar(1000)")
.HasColumnName("Result");
b.Property<int>("Status")
.HasColumnType("int");
b.Property<int>("TriggerCount")
.HasColumnType("int");
b.Property<int>("TryCount")
.HasColumnType("int");
b.Property<string>("Type")
.IsRequired()
.HasMaxLength(200)
.HasColumnType("varchar(200)")
.HasColumnName("Type");
b.HasKey("Id");
b.HasIndex("Name", "Group");
b.ToTable("TK_BackgroundJobs", (string)null);
});
modelBuilder.Entity("LINGYUN.Abp.TaskManagement.BackgroundJobLog", b =>
{
b.Property<long>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("bigint");
b.Property<string>("Exception")
.HasMaxLength(2000)
.HasColumnType("varchar(2000)")
.HasColumnName("Exception");
b.Property<string>("JobGroup")
.HasMaxLength(50)
.HasColumnType("varchar(50)")
.HasColumnName("JobGroup");
b.Property<Guid?>("JobId")
.HasColumnType("char(36)");
b.Property<string>("JobName")
.HasMaxLength(100)
.HasColumnType("varchar(100)")
.HasColumnName("JobName");
b.Property<string>("JobType")
.HasMaxLength(200)
.HasColumnType("varchar(200)")
.HasColumnName("JobType");
b.Property<string>("Message")
.HasMaxLength(1000)
.HasColumnType("varchar(1000)")
.HasColumnName("Message");
b.Property<DateTime>("RunTime")
.HasColumnType("datetime(6)");
b.HasKey("Id");
b.HasIndex("JobGroup", "JobName");
b.ToTable("TK_BackgroundJobLogs", (string)null);
});
#pragma warning restore 612, 618
}
}
}

27
aspnet-core/services/LY.MicroService.TaskManagement.HttpApi.Host/Migrations/20220109033926_Add-Field-Result-With-Background-Job-Info.cs

@ -0,0 +1,27 @@
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace LY.MicroService.TaskManagement.Migrations
{
public partial class AddFieldResultWithBackgroundJobInfo : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AddColumn<string>(
name: "Result",
table: "TK_BackgroundJobs",
type: "varchar(1000)",
maxLength: 1000,
nullable: true)
.Annotation("MySql:CharSet", "utf8mb4");
}
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropColumn(
name: "Result",
table: "TK_BackgroundJobs");
}
}
}

191
aspnet-core/services/LY.MicroService.TaskManagement.HttpApi.Host/Migrations/TaskManagementMigrationsDbContextModelSnapshot.cs

@ -0,0 +1,191 @@
// <auto-generated />
using System;
using LY.MicroService.TaskManagement.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using Volo.Abp.EntityFrameworkCore;
#nullable disable
namespace LY.MicroService.TaskManagement.Migrations
{
[DbContext(typeof(TaskManagementMigrationsDbContext))]
partial class TaskManagementMigrationsDbContextModelSnapshot : ModelSnapshot
{
protected override void BuildModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("_Abp_DatabaseProvider", EfCoreDatabaseProvider.MySql)
.HasAnnotation("ProductVersion", "6.0.1")
.HasAnnotation("Relational:MaxIdentifierLength", 64);
modelBuilder.Entity("LINGYUN.Abp.TaskManagement.BackgroundJobInfo", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("char(36)");
b.Property<string>("Args")
.HasColumnType("longtext")
.HasColumnName("Args");
b.Property<DateTime>("BeginTime")
.HasColumnType("datetime(6)");
b.Property<string>("ConcurrencyStamp")
.IsConcurrencyToken()
.HasMaxLength(40)
.HasColumnType("varchar(40)")
.HasColumnName("ConcurrencyStamp");
b.Property<DateTime>("CreationTime")
.HasColumnType("datetime(6)")
.HasColumnName("CreationTime");
b.Property<Guid?>("CreatorId")
.HasColumnType("char(36)")
.HasColumnName("CreatorId");
b.Property<string>("Cron")
.HasMaxLength(50)
.HasColumnType("varchar(50)")
.HasColumnName("Cron");
b.Property<string>("Description")
.HasMaxLength(255)
.HasColumnType("varchar(255)")
.HasColumnName("Description");
b.Property<DateTime?>("EndTime")
.HasColumnType("datetime(6)");
b.Property<string>("ExtraProperties")
.HasColumnType("longtext")
.HasColumnName("ExtraProperties");
b.Property<string>("Group")
.IsRequired()
.HasMaxLength(50)
.HasColumnType("varchar(50)")
.HasColumnName("Group");
b.Property<int>("Interval")
.HasColumnType("int");
b.Property<bool>("IsAbandoned")
.HasColumnType("tinyint(1)");
b.Property<bool>("IsEnabled")
.HasColumnType("tinyint(1)");
b.Property<int>("JobType")
.HasColumnType("int");
b.Property<DateTime?>("LastModificationTime")
.HasColumnType("datetime(6)")
.HasColumnName("LastModificationTime");
b.Property<Guid?>("LastModifierId")
.HasColumnType("char(36)")
.HasColumnName("LastModifierId");
b.Property<DateTime?>("LastRunTime")
.HasColumnType("datetime(6)");
b.Property<int>("LockTimeOut")
.HasColumnType("int");
b.Property<int>("MaxCount")
.HasColumnType("int");
b.Property<int>("MaxTryCount")
.HasColumnType("int");
b.Property<string>("Name")
.IsRequired()
.HasMaxLength(100)
.HasColumnType("varchar(100)")
.HasColumnName("Name");
b.Property<DateTime?>("NextRunTime")
.HasColumnType("datetime(6)");
b.Property<int>("Priority")
.HasColumnType("int");
b.Property<string>("Result")
.HasMaxLength(1000)
.HasColumnType("varchar(1000)")
.HasColumnName("Result");
b.Property<int>("Status")
.HasColumnType("int");
b.Property<int>("TriggerCount")
.HasColumnType("int");
b.Property<int>("TryCount")
.HasColumnType("int");
b.Property<string>("Type")
.IsRequired()
.HasMaxLength(200)
.HasColumnType("varchar(200)")
.HasColumnName("Type");
b.HasKey("Id");
b.HasIndex("Name", "Group");
b.ToTable("TK_BackgroundJobs", (string)null);
});
modelBuilder.Entity("LINGYUN.Abp.TaskManagement.BackgroundJobLog", b =>
{
b.Property<long>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("bigint");
b.Property<string>("Exception")
.HasMaxLength(2000)
.HasColumnType("varchar(2000)")
.HasColumnName("Exception");
b.Property<string>("JobGroup")
.HasMaxLength(50)
.HasColumnType("varchar(50)")
.HasColumnName("JobGroup");
b.Property<Guid?>("JobId")
.HasColumnType("char(36)");
b.Property<string>("JobName")
.HasMaxLength(100)
.HasColumnType("varchar(100)")
.HasColumnName("JobName");
b.Property<string>("JobType")
.HasMaxLength(200)
.HasColumnType("varchar(200)")
.HasColumnName("JobType");
b.Property<string>("Message")
.HasMaxLength(1000)
.HasColumnType("varchar(1000)")
.HasColumnName("Message");
b.Property<DateTime>("RunTime")
.HasColumnType("datetime(6)");
b.HasKey("Id");
b.HasIndex("JobGroup", "JobName");
b.ToTable("TK_BackgroundJobLogs", (string)null);
});
#pragma warning restore 612, 618
}
}
}

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

@ -6,6 +6,8 @@ using LINGYUN.Abp.LocalizationManagement.EntityFrameworkCore;
using LINGYUN.Abp.MultiTenancy.DbFinder;
using LINGYUN.Abp.Serilog.Enrichers.Application;
using LINGYUN.Abp.Serilog.Enrichers.UniqueId;
using LINGYUN.Abp.TaskManagement;
using LINGYUN.Abp.TaskManagement.EntityFrameworkCore;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.DependencyInjection;
@ -41,9 +43,9 @@ namespace LY.MicroService.TaskManagement;
typeof(AbpAspNetCoreMultiTenancyModule),
typeof(AbpDbFinderMultiTenancyModule),
typeof(AbpBackgroundTasksQuartzModule),
//typeof(TaskManagementApplicationModule),
//typeof(TaskManagementHttpApiModule),
//typeof(TaskManagementEntityFrameworkCoreModule),
typeof(TaskManagementApplicationModule),
typeof(TaskManagementHttpApiModule),
typeof(TaskManagementEntityFrameworkCoreModule),
typeof(AbpFeatureManagementEntityFrameworkCoreModule),
typeof(AbpPermissionManagementEntityFrameworkCoreModule),
typeof(AbpSettingManagementEntityFrameworkCoreModule),

2
aspnet-core/services/LY.MicroService.TaskManagement.HttpApi.Host/appsettings.Development.json

@ -93,7 +93,7 @@
"Override": {
"System": "Warning",
"Microsoft": "Warning",
"DotNetCore": "Debug"
"DotNetCore": "Warning"
}
},
"WriteTo": [

2
aspnet-core/services/LY.MicroService.TaskManagement.HttpApi.Host/appsettings.json

@ -9,7 +9,7 @@
"MinimumLevel": {
"Default": "Debug",
"Override": {
"Microsoft.EntityFrameworkCore": "Debug",
"Microsoft.EntityFrameworkCore": "Warning",
"System": "Information",
"Microsoft": "Information"
}

Loading…
Cancel
Save