diff --git a/apps/vue/src/api/task-management/model/backgroundJobInfoModel.ts b/apps/vue/src/api/task-management/model/backgroundJobInfoModel.ts index 801f13dc3..8d219fa8b 100644 --- a/apps/vue/src/api/task-management/model/backgroundJobInfoModel.ts +++ b/apps/vue/src/api/task-management/model/backgroundJobInfoModel.ts @@ -15,6 +15,12 @@ export enum JobType { Persistent, } +export enum JobSource { + None = -1, + User = 0, + System = 10, +} + export enum JobPriority { Low = 5, BelowNormal = 10, @@ -44,6 +50,7 @@ export interface BackgroundJobInfo extends ExtensibleAuditedEntity, IHas isAbandoned: boolean; interval: number; priority: JobPriority; + source: JobSource; lockTimeOut: number; } @@ -86,4 +93,5 @@ export interface BackgroundJobInfoGetListInput extends PagedAndSortedResultReque isAbandoned?: boolean; jobType?: JobType; priority?: JobPriority; + source?: JobSource; } diff --git a/apps/vue/src/views/task-management/background-jobs/datas/ModalData.ts b/apps/vue/src/views/task-management/background-jobs/datas/ModalData.ts index 8a5f47d47..382839209 100644 --- a/apps/vue/src/views/task-management/background-jobs/datas/ModalData.ts +++ b/apps/vue/src/views/task-management/background-jobs/datas/ModalData.ts @@ -1,7 +1,7 @@ import { useLocalization } from '/@/hooks/abp/useLocalization'; import { FormProps } from '/@/components/Form'; -import { JobStatus, JobType, JobPriority } from '/@/api/task-management/model/backgroundJobInfoModel'; -import { JobStatusMap, JobTypeMap, JobPriorityMap } from './typing'; +import { JobStatus, JobType, JobPriority, JobSource } from '/@/api/task-management/model/backgroundJobInfoModel'; +import { JobStatusMap, JobTypeMap, JobPriorityMap, JobSourceMap } from './typing'; const { L } = useLocalization('TaskManagement', 'AbpUi'); @@ -56,11 +56,25 @@ export function getSearchFormSchemas(): Partial { ], }, }, + { + field: 'source', + component: 'Select', + label: L('DisplayName:Source'), + colProps: { span: 6 }, + defaultValue: JobSource.User, + componentProps: { + options: [ + { label: JobSourceMap[JobSource.None], value: JobSource.None }, + { label: JobSourceMap[JobSource.User], value: JobSource.User }, + { label: JobSourceMap[JobSource.System], value: JobSource.System }, + ], + }, + }, { field: 'beginTime', component: 'DatePicker', label: L('DisplayName:BeginTime'), - colProps: { span: 9 }, + colProps: { span: 6 }, componentProps: { style: { width: '100%', @@ -71,7 +85,7 @@ export function getSearchFormSchemas(): Partial { field: 'endTime', component: 'DatePicker', label: L('DisplayName:EndTime'), - colProps: { span: 9 }, + colProps: { span: 6 }, componentProps: { style: { width: '100%', diff --git a/apps/vue/src/views/task-management/background-jobs/datas/typing.ts b/apps/vue/src/views/task-management/background-jobs/datas/typing.ts index 67929d584..2da2ba9da 100644 --- a/apps/vue/src/views/task-management/background-jobs/datas/typing.ts +++ b/apps/vue/src/views/task-management/background-jobs/datas/typing.ts @@ -1,4 +1,4 @@ -import { JobStatus, JobType, JobPriority } from '/@/api/task-management/model/backgroundJobInfoModel'; +import { JobStatus, JobType, JobPriority, JobSource } from '/@/api/task-management/model/backgroundJobInfoModel'; import { useLocalization } from '/@/hooks/abp/useLocalization'; const { L } = useLocalization('TaskManagement'); @@ -41,3 +41,9 @@ export const JobPriorityColor = { [JobPriority.AboveNormal]: 'orange', [JobPriority.High]: 'red', } + +export const JobSourceMap = { + [JobSource.None]: L('DisplayName:None'), + [JobSource.User]: L('DisplayName:User'), + [JobSource.System]: L('DisplayName:System'), +} diff --git a/aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks.Abstractions/LINGYUN/Abp/BackgroundTasks/JobInfo.cs b/aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks.Abstractions/LINGYUN/Abp/BackgroundTasks/JobInfo.cs index 9eb0348ac..46f7ab78c 100644 --- a/aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks.Abstractions/LINGYUN/Abp/BackgroundTasks/JobInfo.cs +++ b/aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks.Abstractions/LINGYUN/Abp/BackgroundTasks/JobInfo.cs @@ -30,9 +30,13 @@ public class JobInfo /// public string Result { get; set; } /// + /// 作业来源 + /// + public JobSource Source { get; set; } = JobSource.None; + /// /// 任务参数 /// - public IDictionary Args { get; set; } + public IDictionary Args { get; set; } = new Dictionary(); /// /// 任务状态 /// diff --git a/aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks.Abstractions/LINGYUN/Abp/BackgroundTasks/JobSource.cs b/aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks.Abstractions/LINGYUN/Abp/BackgroundTasks/JobSource.cs new file mode 100644 index 000000000..86833cc3e --- /dev/null +++ b/aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks.Abstractions/LINGYUN/Abp/BackgroundTasks/JobSource.cs @@ -0,0 +1,19 @@ +namespace LINGYUN.Abp.BackgroundTasks; +/// +/// 作业来源 +/// +public enum JobSource +{ + /// + /// 未定义 + /// + None = -1, + /// + /// 用户 + /// + User = 0, + /// + /// 系统内置 + /// + System = 10, +} diff --git a/aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks/LINGYUN/Abp/BackgroundTasks/BackgroundJobManager.cs b/aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks/LINGYUN/Abp/BackgroundTasks/BackgroundJobManager.cs index 11904df52..a81f67921 100644 --- a/aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks/LINGYUN/Abp/BackgroundTasks/BackgroundJobManager.cs +++ b/aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks/LINGYUN/Abp/BackgroundTasks/BackgroundJobManager.cs @@ -65,6 +65,7 @@ public class BackgroundJobManager : IBackgroundJobManager, ITransientDependency Name = jobId.ToString(), Group = "BackgroundJobs", Priority = ConverForm(priority), + Source = JobSource.System, BeginTime = DateTime.Now, Args = jobArgs, Description = "From the framework background jobs", diff --git a/aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks/LINGYUN/Abp/BackgroundTasks/BackgroundWorkerAdapter.cs b/aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks/LINGYUN/Abp/BackgroundTasks/BackgroundWorkerAdapter.cs index 71588b39c..4797acaca 100644 --- a/aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks/LINGYUN/Abp/BackgroundTasks/BackgroundWorkerAdapter.cs +++ b/aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks/LINGYUN/Abp/BackgroundTasks/BackgroundWorkerAdapter.cs @@ -74,6 +74,7 @@ public class BackgroundWorkerAdapter : BackgroundWorkerBase, IBackgroun Name = workerType.FullName, Group = "BackgroundWorkers", Priority = JobPriority.Normal, + Source = JobSource.System, BeginTime = Clock.Now, Args = jobArgs, Description = "From the framework background workers", diff --git a/aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks/LINGYUN/Abp/BackgroundTasks/Internal/DefaultBackgroundWorker.cs b/aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks/LINGYUN/Abp/BackgroundTasks/Internal/DefaultBackgroundWorker.cs index 89e75e449..a8920f34e 100644 --- a/aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks/LINGYUN/Abp/BackgroundTasks/Internal/DefaultBackgroundWorker.cs +++ b/aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks/LINGYUN/Abp/BackgroundTasks/Internal/DefaultBackgroundWorker.cs @@ -62,6 +62,7 @@ internal class DefaultBackgroundWorker : BackgroundService Cron = _options.JobFetchCronExpression, JobType = JobType.Period, Priority = JobPriority.High, + Source = JobSource.System, LockTimeOut = _options.JobFetchLockTimeOut, Type = typeof(BackgroundPollingJob).AssemblyQualifiedName, }; @@ -82,6 +83,7 @@ internal class DefaultBackgroundWorker : BackgroundService Cron = _options.JobCleanCronExpression, JobType = JobType.Period, Priority = JobPriority.High, + Source = JobSource.System, Type = typeof(BackgroundCleaningJob).AssemblyQualifiedName, }; } diff --git a/aspnet-core/modules/task-management/LINGYUN.Abp.TaskManagement.Application.Contracts/LINGYUN/Abp/TaskManagement/BackgroundJobInfoDto.cs b/aspnet-core/modules/task-management/LINGYUN.Abp.TaskManagement.Application.Contracts/LINGYUN/Abp/TaskManagement/BackgroundJobInfoDto.cs index b9317e687..da915aa09 100644 --- a/aspnet-core/modules/task-management/LINGYUN.Abp.TaskManagement.Application.Contracts/LINGYUN/Abp/TaskManagement/BackgroundJobInfoDto.cs +++ b/aspnet-core/modules/task-management/LINGYUN.Abp.TaskManagement.Application.Contracts/LINGYUN/Abp/TaskManagement/BackgroundJobInfoDto.cs @@ -97,6 +97,10 @@ public class BackgroundJobInfoDto : ExtensibleAuditedEntityDto, IHasConc /// public JobPriority Priority { get; set; } /// + /// 作业来源 + /// + public JobSource Source { get; set; } + /// /// 任务独占超时时长(秒) /// 0或更小不生效 /// diff --git a/aspnet-core/modules/task-management/LINGYUN.Abp.TaskManagement.Application.Contracts/LINGYUN/Abp/TaskManagement/BackgroundJobInfoGetListInput.cs b/aspnet-core/modules/task-management/LINGYUN.Abp.TaskManagement.Application.Contracts/LINGYUN/Abp/TaskManagement/BackgroundJobInfoGetListInput.cs index 8f0ccf86b..beb76ae92 100644 --- a/aspnet-core/modules/task-management/LINGYUN.Abp.TaskManagement.Application.Contracts/LINGYUN/Abp/TaskManagement/BackgroundJobInfoGetListInput.cs +++ b/aspnet-core/modules/task-management/LINGYUN.Abp.TaskManagement.Application.Contracts/LINGYUN/Abp/TaskManagement/BackgroundJobInfoGetListInput.cs @@ -62,4 +62,8 @@ public class BackgroundJobInfoGetListInput: PagedAndSortedResultRequestDto /// 优先级 /// public JobPriority? Priority { get; set; } + /// + /// 作业来源 + /// + public JobSource? Source { get; set; } } diff --git a/aspnet-core/modules/task-management/LINGYUN.Abp.TaskManagement.Application.Contracts/LINGYUN/Abp/TaskManagement/Permissions/TaskManagementPermissionDefinitionProvider.cs b/aspnet-core/modules/task-management/LINGYUN.Abp.TaskManagement.Application.Contracts/LINGYUN/Abp/TaskManagement/Permissions/TaskManagementPermissionDefinitionProvider.cs index a399e64c2..6e4985ed9 100644 --- a/aspnet-core/modules/task-management/LINGYUN.Abp.TaskManagement.Application.Contracts/LINGYUN/Abp/TaskManagement/Permissions/TaskManagementPermissionDefinitionProvider.cs +++ b/aspnet-core/modules/task-management/LINGYUN.Abp.TaskManagement.Application.Contracts/LINGYUN/Abp/TaskManagement/Permissions/TaskManagementPermissionDefinitionProvider.cs @@ -39,6 +39,9 @@ public class TaskManagementPermissionDefinitionProvider : PermissionDefinitionPr backgroundJobs.AddChild( TaskManagementPermissions.BackgroundJobs.Stop, L("Permissions:StopJob")); + backgroundJobs.AddChild( + TaskManagementPermissions.BackgroundJobs.ManageSystemJobs, + L("Permissions:ManageSystemJobs")); var backgroundJobLogs = group.AddPermission( TaskManagementPermissions.BackgroundJobLogs.Default, diff --git a/aspnet-core/modules/task-management/LINGYUN.Abp.TaskManagement.Application.Contracts/LINGYUN/Abp/TaskManagement/Permissions/TaskManagementPermissions.cs b/aspnet-core/modules/task-management/LINGYUN.Abp.TaskManagement.Application.Contracts/LINGYUN/Abp/TaskManagement/Permissions/TaskManagementPermissions.cs index 364343119..85f84bebd 100644 --- a/aspnet-core/modules/task-management/LINGYUN.Abp.TaskManagement.Application.Contracts/LINGYUN/Abp/TaskManagement/Permissions/TaskManagementPermissions.cs +++ b/aspnet-core/modules/task-management/LINGYUN.Abp.TaskManagement.Application.Contracts/LINGYUN/Abp/TaskManagement/Permissions/TaskManagementPermissions.cs @@ -15,6 +15,11 @@ public static class TaskManagementPermissions public const string Resume = Default + ".Resume"; public const string Start = Default + ".Start"; public const string Stop = Default + ".Stop"; + /// + /// 是否允许管理系统内置作业 + /// 通常内置作业是由程序运行中产生,需要控制用户行为 + /// + public const string ManageSystemJobs = Default + ".ManageSystemJobs"; } public static class BackgroundJobLogs diff --git a/aspnet-core/modules/task-management/LINGYUN.Abp.TaskManagement.Application/LINGYUN/Abp/TaskManagement/BackgroundJobInfoAppService.cs b/aspnet-core/modules/task-management/LINGYUN.Abp.TaskManagement.Application/LINGYUN/Abp/TaskManagement/BackgroundJobInfoAppService.cs index 2223a1175..00e44e594 100644 --- a/aspnet-core/modules/task-management/LINGYUN.Abp.TaskManagement.Application/LINGYUN/Abp/TaskManagement/BackgroundJobInfoAppService.cs +++ b/aspnet-core/modules/task-management/LINGYUN.Abp.TaskManagement.Application/LINGYUN/Abp/TaskManagement/BackgroundJobInfoAppService.cs @@ -1,7 +1,6 @@ using LINGYUN.Abp.BackgroundTasks; using LINGYUN.Abp.TaskManagement.Permissions; using Microsoft.AspNetCore.Authorization; -using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; @@ -45,6 +44,7 @@ public class BackgroundJobInfoAppService : TaskManagementApplicationService, IBa input.BeginTime, input.EndTime, input.Priority, + JobSource.User, input.MaxCount, input.MaxTryCount, CurrentTenant.Id); @@ -66,6 +66,8 @@ public class BackgroundJobInfoAppService : TaskManagementApplicationService, IBa { var backgroundJobInfo = await BackgroundJobInfoRepository.GetAsync(id); + await CheckIfChangeSystemJob(backgroundJobInfo); + await BackgroundJobManager.DeleteAsync(backgroundJobInfo); } @@ -92,6 +94,7 @@ public class BackgroundJobInfoAppService : TaskManagementApplicationService, IBa Group = input.Group, Name = input.Name, Priority = input.Priority, + Source = input.Source, Status = input.Status, Type = input.Type }; @@ -108,6 +111,8 @@ public class BackgroundJobInfoAppService : TaskManagementApplicationService, IBa { var backgroundJobInfo = await BackgroundJobInfoRepository.GetAsync(id); + await CheckIfChangeSystemJob(backgroundJobInfo); + await BackgroundJobManager.PauseAsync(backgroundJobInfo); } @@ -116,6 +121,8 @@ public class BackgroundJobInfoAppService : TaskManagementApplicationService, IBa { var backgroundJobInfo = await BackgroundJobInfoRepository.GetAsync(id); + await CheckIfChangeSystemJob(backgroundJobInfo); + await BackgroundJobManager.ResumeAsync(backgroundJobInfo); } @@ -124,6 +131,8 @@ public class BackgroundJobInfoAppService : TaskManagementApplicationService, IBa { var backgroundJobInfo = await BackgroundJobInfoRepository.GetAsync(id); + await CheckIfChangeSystemJob(backgroundJobInfo); + await BackgroundJobManager.TriggerAsync(backgroundJobInfo); } @@ -132,6 +141,8 @@ public class BackgroundJobInfoAppService : TaskManagementApplicationService, IBa { var backgroundJobInfo = await BackgroundJobInfoRepository.GetAsync(id); + await CheckIfChangeSystemJob(backgroundJobInfo); + await BackgroundJobManager.StopAsync(backgroundJobInfo); } @@ -140,6 +151,8 @@ public class BackgroundJobInfoAppService : TaskManagementApplicationService, IBa { var backgroundJobInfo = await BackgroundJobInfoRepository.GetAsync(id); + await CheckIfChangeSystemJob(backgroundJobInfo); + await BackgroundJobManager.QueueAsync(backgroundJobInfo); } @@ -148,6 +161,8 @@ public class BackgroundJobInfoAppService : TaskManagementApplicationService, IBa { var backgroundJobInfo = await BackgroundJobInfoRepository.GetAsync(id); + await CheckIfChangeSystemJob(backgroundJobInfo); + var resetJob = backgroundJobInfo.JobType == input.JobType; UpdateByInput(backgroundJobInfo, input); @@ -168,6 +183,11 @@ public class BackgroundJobInfoAppService : TaskManagementApplicationService, IBa } var jobs = await GetListAsync(input); + if (jobs.Any(job => job.Source == JobSource.System)) + { + await AuthorizationService.CheckAsync(TaskManagementPermissions.BackgroundJobs.ManageSystemJobs); + } + await BackgroundJobManager.BulkDeleteAsync(jobs); } @@ -180,6 +200,11 @@ public class BackgroundJobInfoAppService : TaskManagementApplicationService, IBa } var jobs = await GetListAsync(input); + if (jobs.Any(job => job.Source == JobSource.System)) + { + await AuthorizationService.CheckAsync(TaskManagementPermissions.BackgroundJobs.ManageSystemJobs); + } + await BackgroundJobManager.BulkStopAsync(jobs); } @@ -192,6 +217,11 @@ public class BackgroundJobInfoAppService : TaskManagementApplicationService, IBa } var jobs = await GetListAsync(input); + if (jobs.Any(job => job.Source == JobSource.System)) + { + await AuthorizationService.CheckAsync(TaskManagementPermissions.BackgroundJobs.ManageSystemJobs); + } + await BackgroundJobManager.BulkQueueAsync(jobs); } @@ -204,6 +234,11 @@ public class BackgroundJobInfoAppService : TaskManagementApplicationService, IBa } var jobs = await GetListAsync(input); + if (jobs.Any(job => job.Source == JobSource.System)) + { + await AuthorizationService.CheckAsync(TaskManagementPermissions.BackgroundJobs.ManageSystemJobs); + } + await BackgroundJobManager.BulkTriggerAsync(jobs); } @@ -216,6 +251,11 @@ public class BackgroundJobInfoAppService : TaskManagementApplicationService, IBa } var jobs = await GetListAsync(input); + if (jobs.Any(job => job.Source == JobSource.System)) + { + await AuthorizationService.CheckAsync(TaskManagementPermissions.BackgroundJobs.ManageSystemJobs); + } + await BackgroundJobManager.BulkResumeAsync(jobs); } @@ -228,6 +268,11 @@ public class BackgroundJobInfoAppService : TaskManagementApplicationService, IBa } var jobs = await GetListAsync(input); + if (jobs.Any(job => job.Source == JobSource.System)) + { + await AuthorizationService.CheckAsync(TaskManagementPermissions.BackgroundJobs.ManageSystemJobs); + } + await BackgroundJobManager.BulkPauseAsync(jobs); } @@ -262,4 +307,12 @@ public class BackgroundJobInfoAppService : TaskManagementApplicationService, IBa break; } } + + protected async virtual Task CheckIfChangeSystemJob(BackgroundJobInfo backgroundJobInfo) + { + if (backgroundJobInfo.Source == JobSource.System) + { + await AuthorizationService.CheckAsync(TaskManagementPermissions.BackgroundJobs.ManageSystemJobs); + } + } } diff --git a/aspnet-core/modules/task-management/LINGYUN.Abp.TaskManagement.Domain.Shared/LINGYUN/Abp/TaskManagement/Localization/Resources/en.json b/aspnet-core/modules/task-management/LINGYUN.Abp.TaskManagement.Domain.Shared/LINGYUN/Abp/TaskManagement/Localization/Resources/en.json index cca6d1218..e383ee657 100644 --- a/aspnet-core/modules/task-management/LINGYUN.Abp.TaskManagement.Domain.Shared/LINGYUN/Abp/TaskManagement/Localization/Resources/en.json +++ b/aspnet-core/modules/task-management/LINGYUN.Abp.TaskManagement.Domain.Shared/LINGYUN/Abp/TaskManagement/Localization/Resources/en.json @@ -11,6 +11,7 @@ "Permissions:ResumeJob": "Resume Job", "Permissions:StartJob": "Start Job", "Permissions:StopJob": "Stop Job", + "Permissions:ManageSystemJobs": "Manage System Jobs", "Permissions:BackgroundJobLogs": "BackgroundJobs Logs", "Permissions:DeleteJobLogs": "Delete Job Logs", "TaskManagement:01000": "A job named {Name} already exists in the Group {Group}!", @@ -66,6 +67,8 @@ "DisplayName:Normal": "Normal", "DisplayName:AboveNormal": "Above Normal", "DisplayName:High": "High", + "DisplayName:User": "User", + "DisplayName:System": "System", "BackgroundJobs": "Jobs", "BackgroundJobDetail": "Job Detail", "BackgroundJobLogs": "Job Logs", diff --git a/aspnet-core/modules/task-management/LINGYUN.Abp.TaskManagement.Domain.Shared/LINGYUN/Abp/TaskManagement/Localization/Resources/zh-Hans.json b/aspnet-core/modules/task-management/LINGYUN.Abp.TaskManagement.Domain.Shared/LINGYUN/Abp/TaskManagement/Localization/Resources/zh-Hans.json index 6d271d47a..1f5d9dc79 100644 --- a/aspnet-core/modules/task-management/LINGYUN.Abp.TaskManagement.Domain.Shared/LINGYUN/Abp/TaskManagement/Localization/Resources/zh-Hans.json +++ b/aspnet-core/modules/task-management/LINGYUN.Abp.TaskManagement.Domain.Shared/LINGYUN/Abp/TaskManagement/Localization/Resources/zh-Hans.json @@ -11,6 +11,7 @@ "Permissions:ResumeJob": "恢复作业", "Permissions:StartJob": "启动作业", "Permissions:StopJob": "停止作业", + "Permissions:ManageSystemJobs": "管理系统作业", "Permissions:BackgroundJobLogs": "日志管理", "Permissions:DeleteJobLogs": "删除作业日志", "TaskManagement:01000": "分组 {Group} 中已经存在一个名称为 {Name} 的作业!", @@ -66,6 +67,8 @@ "DisplayName:Normal": "正常", "DisplayName:AboveNormal": "高于正常", "DisplayName:High": "高", + "DisplayName:User": "用户", + "DisplayName:System": "系统内置", "BackgroundJobs": "作业列表", "BackgroundJobDetail": "作业详情", "BackgroundJobLogs": "作业日志", diff --git a/aspnet-core/modules/task-management/LINGYUN.Abp.TaskManagement.Domain/LINGYUN/Abp/TaskManagement/BackgroundJobInfo.cs b/aspnet-core/modules/task-management/LINGYUN.Abp.TaskManagement.Domain/LINGYUN/Abp/TaskManagement/BackgroundJobInfo.cs index 2e58ab1ae..bb202421c 100644 --- a/aspnet-core/modules/task-management/LINGYUN.Abp.TaskManagement.Domain/LINGYUN/Abp/TaskManagement/BackgroundJobInfo.cs +++ b/aspnet-core/modules/task-management/LINGYUN.Abp.TaskManagement.Domain/LINGYUN/Abp/TaskManagement/BackgroundJobInfo.cs @@ -73,6 +73,10 @@ public class BackgroundJobInfo : AuditedAggregateRoot, IMultiTenant /// public virtual string Cron { get; protected set; } /// + /// 作业来源 + /// + public virtual JobSource Source { get; protected set; } + /// /// 任务优先级 /// public virtual JobPriority Priority { get; protected set; } @@ -115,6 +119,7 @@ public class BackgroundJobInfo : AuditedAggregateRoot, IMultiTenant DateTime beginTime, DateTime? endTime = null, JobPriority priority = JobPriority.Normal, + JobSource source = JobSource.None, int maxCount = 0, int maxTryCount = 50, Guid? tenantId = null) : base(id) @@ -123,6 +128,7 @@ public class BackgroundJobInfo : AuditedAggregateRoot, IMultiTenant Group = Check.NotNullOrWhiteSpace(group, nameof(group), BackgroundJobInfoConsts.MaxGroupLength); Type = Check.NotNullOrWhiteSpace(type, nameof(type), BackgroundJobInfoConsts.MaxTypeLength); Priority = priority; + Source = source; BeginTime = beginTime; EndTime = endTime; diff --git a/aspnet-core/modules/task-management/LINGYUN.Abp.TaskManagement.Domain/LINGYUN/Abp/TaskManagement/BackgroundJobInfoFilter.cs b/aspnet-core/modules/task-management/LINGYUN.Abp.TaskManagement.Domain/LINGYUN/Abp/TaskManagement/BackgroundJobInfoFilter.cs index 5d7347f8b..bece73b02 100644 --- a/aspnet-core/modules/task-management/LINGYUN.Abp.TaskManagement.Domain/LINGYUN/Abp/TaskManagement/BackgroundJobInfoFilter.cs +++ b/aspnet-core/modules/task-management/LINGYUN.Abp.TaskManagement.Domain/LINGYUN/Abp/TaskManagement/BackgroundJobInfoFilter.cs @@ -64,4 +64,8 @@ public class BackgroundJobInfoFilter /// 优先级 /// public JobPriority? Priority { get; set; } + /// + /// 作业来源 + /// + public JobSource? Source { get; set; } } diff --git a/aspnet-core/modules/task-management/LINGYUN.Abp.TaskManagement.Domain/LINGYUN/Abp/TaskManagement/BackgroundJobStore.cs b/aspnet-core/modules/task-management/LINGYUN.Abp.TaskManagement.Domain/LINGYUN/Abp/TaskManagement/BackgroundJobStore.cs index 403e4f3f4..b48cd20a7 100644 --- a/aspnet-core/modules/task-management/LINGYUN.Abp.TaskManagement.Domain/LINGYUN/Abp/TaskManagement/BackgroundJobStore.cs +++ b/aspnet-core/modules/task-management/LINGYUN.Abp.TaskManagement.Domain/LINGYUN/Abp/TaskManagement/BackgroundJobStore.cs @@ -79,6 +79,7 @@ public class BackgroundJobStore : IJobStore, ITransientDependency jobInfo.BeginTime, jobInfo.EndTime, jobInfo.Priority, + jobInfo.Source, jobInfo.MaxCount, jobInfo.MaxTryCount) { diff --git a/aspnet-core/modules/task-management/LINGYUN.Abp.TaskManagement.EntityFrameworkCore/LINGYUN/Abp/TaskManagement/EntityFrameworkCore/EfCoreBackgroundJobInfoRepository.cs b/aspnet-core/modules/task-management/LINGYUN.Abp.TaskManagement.EntityFrameworkCore/LINGYUN/Abp/TaskManagement/EntityFrameworkCore/EfCoreBackgroundJobInfoRepository.cs index 80d38a979..073a75e92 100644 --- a/aspnet-core/modules/task-management/LINGYUN.Abp.TaskManagement.EntityFrameworkCore/LINGYUN/Abp/TaskManagement/EntityFrameworkCore/EfCoreBackgroundJobInfoRepository.cs +++ b/aspnet-core/modules/task-management/LINGYUN.Abp.TaskManagement.EntityFrameworkCore/LINGYUN/Abp/TaskManagement/EntityFrameworkCore/EfCoreBackgroundJobInfoRepository.cs @@ -63,6 +63,7 @@ public class EfCoreBackgroundJobInfoRepository : JobType = x.JobType, Status = x.Status, Priority = x.Priority, + Source = x.Source, LastRunTime = x.LastRunTime, LockTimeOut = x.LockTimeOut, Result = x.Result, @@ -103,43 +104,13 @@ public class EfCoreBackgroundJobInfoRepository : public virtual async Task GetCountAsync(BackgroundJobInfoFilter filter, CancellationToken cancellationToken = default) { - return await (await GetDbSetAsync()) - .WhereIf(!filter.Type.IsNullOrWhiteSpace(), x => x.Type.Contains(filter.Type)) - .WhereIf(!filter.Group.IsNullOrWhiteSpace(), x => x.Group.Equals(filter.Group)) - .WhereIf(!filter.Name.IsNullOrWhiteSpace(), x => x.Name.Equals(filter.Name)) - .WhereIf(!filter.Filter.IsNullOrWhiteSpace(), x => x.Name.Contains(filter.Filter) || - x.Group.Contains(filter.Filter) || x.Type.Contains(filter.Filter) || x.Description.Contains(filter.Filter)) - .WhereIf(filter.JobType.HasValue, x => x.JobType == filter.JobType) - .WhereIf(filter.Priority.HasValue, x => x.Priority == filter.Priority.Value) - .WhereIf(filter.Status.HasValue, x => x.Status == filter.Status.Value) - .WhereIf(filter.IsAbandoned.HasValue, x => x.IsAbandoned == filter.IsAbandoned.Value) - .WhereIf(filter.BeginLastRunTime.HasValue, x => filter.BeginLastRunTime.Value.CompareTo(x.LastRunTime) <= 0) - .WhereIf(filter.EndLastRunTime.HasValue, x => filter.EndLastRunTime.Value.CompareTo(x.LastRunTime) >= 0) - .WhereIf(filter.BeginTime.HasValue, x => x.BeginTime.CompareTo(x.BeginTime) >= 0) - .WhereIf(filter.EndTime.HasValue, x => filter.EndTime.Value.CompareTo(x.EndTime) >= 0) - .WhereIf(filter.BeginCreationTime.HasValue, x => x.CreationTime.CompareTo(filter.BeginCreationTime.Value) >= 0) - .WhereIf(filter.EndCreationTime.HasValue, x => x.CreationTime.CompareTo(filter.EndCreationTime.Value) <= 0) + return await ApplyFilter(await GetDbSetAsync(), filter) .CountAsync(GetCancellationToken(cancellationToken)); } public virtual async Task> GetListAsync(BackgroundJobInfoFilter filter, string sorting = "Name", int maxResultCount = 10, int skipCount = 0, CancellationToken cancellationToken = default) { - return await (await GetDbSetAsync()) - .WhereIf(!filter.Type.IsNullOrWhiteSpace(), x => x.Type.Contains(filter.Type)) - .WhereIf(!filter.Group.IsNullOrWhiteSpace(), x => x.Group.Equals(filter.Group)) - .WhereIf(!filter.Name.IsNullOrWhiteSpace(), x => x.Name.Equals(filter.Name)) - .WhereIf(!filter.Filter.IsNullOrWhiteSpace(), x => x.Name.Contains(filter.Filter) || - x.Group.Contains(filter.Filter) || x.Type.Contains(filter.Filter) || x.Description.Contains(filter.Filter)) - .WhereIf(filter.JobType.HasValue, x => x.JobType == filter.JobType) - .WhereIf(filter.Status.HasValue, x => x.Status == filter.Status.Value) - .WhereIf(filter.Priority.HasValue, x => x.Priority == filter.Priority.Value) - .WhereIf(filter.IsAbandoned.HasValue, x => x.IsAbandoned == filter.IsAbandoned.Value) - .WhereIf(filter.BeginLastRunTime.HasValue, x => filter.BeginLastRunTime.Value.CompareTo(x.LastRunTime) <= 0) - .WhereIf(filter.EndLastRunTime.HasValue, x => filter.EndLastRunTime.Value.CompareTo(x.LastRunTime) >= 0) - .WhereIf(filter.BeginTime.HasValue, x => x.BeginTime.CompareTo(x.BeginTime) >= 0) - .WhereIf(filter.EndTime.HasValue, x => filter.EndTime.Value.CompareTo(x.EndTime) >= 0) - .WhereIf(filter.BeginCreationTime.HasValue, x => x.CreationTime.CompareTo(filter.BeginCreationTime.Value) >= 0) - .WhereIf(filter.EndCreationTime.HasValue, x => x.CreationTime.CompareTo(filter.EndCreationTime.Value) <= 0) + return await ApplyFilter(await GetDbSetAsync(), filter) .OrderBy(sorting ?? $"{nameof(BackgroundJobInfo.CreationTime)} DESC") .PageBy(skipCount, maxResultCount) .ToListAsync(GetCancellationToken(cancellationToken)); @@ -161,4 +132,27 @@ public class EfCoreBackgroundJobInfoRepository : .AsNoTracking() .ToListAsync(GetCancellationToken(cancellationToken)); } + + protected virtual IQueryable ApplyFilter( + IQueryable queryable, + BackgroundJobInfoFilter filter) + { + return queryable + .WhereIf(!filter.Type.IsNullOrWhiteSpace(), x => x.Type.Contains(filter.Type)) + .WhereIf(!filter.Group.IsNullOrWhiteSpace(), x => x.Group.Equals(filter.Group)) + .WhereIf(!filter.Name.IsNullOrWhiteSpace(), x => x.Name.Equals(filter.Name)) + .WhereIf(!filter.Filter.IsNullOrWhiteSpace(), x => x.Name.Contains(filter.Filter) || + x.Group.Contains(filter.Filter) || x.Type.Contains(filter.Filter) || x.Description.Contains(filter.Filter)) + .WhereIf(filter.JobType.HasValue, x => x.JobType == filter.JobType) + .WhereIf(filter.Status.HasValue, x => x.Status == filter.Status.Value) + .WhereIf(filter.Priority.HasValue, x => x.Priority == filter.Priority.Value) + .WhereIf(filter.Source.HasValue, x => x.Source == filter.Source.Value) + .WhereIf(filter.IsAbandoned.HasValue, x => x.IsAbandoned == filter.IsAbandoned.Value) + .WhereIf(filter.BeginLastRunTime.HasValue, x => filter.BeginLastRunTime.Value.CompareTo(x.LastRunTime) <= 0) + .WhereIf(filter.EndLastRunTime.HasValue, x => filter.EndLastRunTime.Value.CompareTo(x.LastRunTime) >= 0) + .WhereIf(filter.BeginTime.HasValue, x => x.BeginTime.CompareTo(x.BeginTime) >= 0) + .WhereIf(filter.EndTime.HasValue, x => filter.EndTime.Value.CompareTo(x.EndTime) >= 0) + .WhereIf(filter.BeginCreationTime.HasValue, x => x.CreationTime.CompareTo(filter.BeginCreationTime.Value) >= 0) + .WhereIf(filter.EndCreationTime.HasValue, x => x.CreationTime.CompareTo(filter.EndCreationTime.Value) <= 0); + } } diff --git a/aspnet-core/modules/task-management/LINGYUN.Abp.TaskManagement.EntityFrameworkCore/LINGYUN/Abp/TaskManagement/EntityFrameworkCore/TaskManagementDbContextModelCreatingExtensions.cs b/aspnet-core/modules/task-management/LINGYUN.Abp.TaskManagement.EntityFrameworkCore/LINGYUN/Abp/TaskManagement/EntityFrameworkCore/TaskManagementDbContextModelCreatingExtensions.cs index 21e455585..36c6ca547 100644 --- a/aspnet-core/modules/task-management/LINGYUN.Abp.TaskManagement.EntityFrameworkCore/LINGYUN/Abp/TaskManagement/EntityFrameworkCore/TaskManagementDbContextModelCreatingExtensions.cs +++ b/aspnet-core/modules/task-management/LINGYUN.Abp.TaskManagement.EntityFrameworkCore/LINGYUN/Abp/TaskManagement/EntityFrameworkCore/TaskManagementDbContextModelCreatingExtensions.cs @@ -1,4 +1,5 @@ -using Microsoft.EntityFrameworkCore; +using LINGYUN.Abp.BackgroundTasks; +using Microsoft.EntityFrameworkCore; using System; using Volo.Abp; using Volo.Abp.EntityFrameworkCore.Modeling; @@ -51,6 +52,10 @@ public static class TaskManagementDbContextModelCreatingExtensions .HasConversion(new ExtraPropertiesValueConverter(b.Metadata.ClrType)) .Metadata.SetValueComparer(new ExtraPropertyDictionaryValueComparer()); + b.Property(p => p.Source) + .HasColumnName(nameof(BackgroundJobInfo.Source)) + .HasDefaultValue(JobSource.None); + b.ConfigureByConvention(); b.HasIndex(p => new { p.Name, p.Group }); diff --git a/aspnet-core/services/LY.MicroService.TaskManagement.HttpApi.Host/EventBus/Handlers/TenantSynchronizer.cs b/aspnet-core/services/LY.MicroService.TaskManagement.HttpApi.Host/EventBus/Handlers/TenantSynchronizer.cs index b25a5987b..08abf463c 100644 --- a/aspnet-core/services/LY.MicroService.TaskManagement.HttpApi.Host/EventBus/Handlers/TenantSynchronizer.cs +++ b/aspnet-core/services/LY.MicroService.TaskManagement.HttpApi.Host/EventBus/Handlers/TenantSynchronizer.cs @@ -116,6 +116,7 @@ namespace LY.MicroService.TaskManagement.EventBus.Handlers Cron = Options.JobFetchCronExpression, JobType = JobType.Period, Priority = JobPriority.High, + Source = JobSource.System, LockTimeOut = Options.JobFetchLockTimeOut, TenantId = tenantId, Type = typeof(BackgroundPollingJob).AssemblyQualifiedName, @@ -137,6 +138,7 @@ namespace LY.MicroService.TaskManagement.EventBus.Handlers Cron = Options.JobCleanCronExpression, JobType = JobType.Period, Priority = JobPriority.High, + Source = JobSource.System, TenantId = tenantId, Type = typeof(BackgroundCleaningJob).AssemblyQualifiedName, }; diff --git a/aspnet-core/services/LY.MicroService.TaskManagement.HttpApi.Host/Migrations/20220330013146_Add-Field-Source-With-BackgroundJobInfo.Designer.cs b/aspnet-core/services/LY.MicroService.TaskManagement.HttpApi.Host/Migrations/20220330013146_Add-Field-Source-With-BackgroundJobInfo.Designer.cs new file mode 100644 index 000000000..72051148a --- /dev/null +++ b/aspnet-core/services/LY.MicroService.TaskManagement.HttpApi.Host/Migrations/20220330013146_Add-Field-Source-With-BackgroundJobInfo.Designer.cs @@ -0,0 +1,208 @@ +// +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("20220330013146_Add-Field-Source-With-BackgroundJobInfo")] + partial class AddFieldSourceWithBackgroundJobInfo + { + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("_Abp_DatabaseProvider", EfCoreDatabaseProvider.MySql) + .HasAnnotation("ProductVersion", "6.0.3") + .HasAnnotation("Relational:MaxIdentifierLength", 64); + + modelBuilder.Entity("LINGYUN.Abp.TaskManagement.BackgroundJobInfo", b => + { + b.Property("Id") + .HasColumnType("varchar(255)"); + + b.Property("Args") + .HasColumnType("longtext") + .HasColumnName("Args"); + + b.Property("BeginTime") + .HasColumnType("datetime(6)"); + + b.Property("ConcurrencyStamp") + .IsConcurrencyToken() + .HasMaxLength(40) + .HasColumnType("varchar(40)") + .HasColumnName("ConcurrencyStamp"); + + b.Property("CreationTime") + .HasColumnType("datetime(6)") + .HasColumnName("CreationTime"); + + b.Property("CreatorId") + .HasColumnType("char(36)") + .HasColumnName("CreatorId"); + + b.Property("Cron") + .HasMaxLength(50) + .HasColumnType("varchar(50)") + .HasColumnName("Cron"); + + b.Property("Description") + .HasMaxLength(255) + .HasColumnType("varchar(255)") + .HasColumnName("Description"); + + b.Property("EndTime") + .HasColumnType("datetime(6)"); + + b.Property("ExtraProperties") + .HasColumnType("longtext") + .HasColumnName("ExtraProperties"); + + b.Property("Group") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("varchar(50)") + .HasColumnName("Group"); + + b.Property("Interval") + .HasColumnType("int"); + + b.Property("IsAbandoned") + .HasColumnType("tinyint(1)"); + + b.Property("IsEnabled") + .HasColumnType("tinyint(1)"); + + b.Property("JobType") + .HasColumnType("int"); + + b.Property("LastModificationTime") + .HasColumnType("datetime(6)") + .HasColumnName("LastModificationTime"); + + b.Property("LastModifierId") + .HasColumnType("char(36)") + .HasColumnName("LastModifierId"); + + b.Property("LastRunTime") + .HasColumnType("datetime(6)"); + + b.Property("LockTimeOut") + .HasColumnType("int"); + + b.Property("MaxCount") + .HasColumnType("int"); + + b.Property("MaxTryCount") + .HasColumnType("int"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(100) + .HasColumnType("varchar(100)") + .HasColumnName("Name"); + + b.Property("NextRunTime") + .HasColumnType("datetime(6)"); + + b.Property("Priority") + .HasColumnType("int"); + + b.Property("Result") + .HasMaxLength(1000) + .HasColumnType("varchar(1000)") + .HasColumnName("Result"); + + b.Property("Source") + .ValueGeneratedOnAdd() + .HasColumnType("int") + .HasDefaultValue(-1) + .HasColumnName("Source"); + + b.Property("Status") + .HasColumnType("int"); + + b.Property("TenantId") + .HasColumnType("char(36)") + .HasColumnName("TenantId"); + + b.Property("TriggerCount") + .HasColumnType("int"); + + b.Property("TryCount") + .HasColumnType("int"); + + b.Property("Type") + .IsRequired() + .HasMaxLength(1000) + .HasColumnType("varchar(1000)") + .HasColumnName("Type"); + + b.HasKey("Id"); + + b.HasIndex("Name", "Group"); + + b.ToTable("TK_BackgroundJobs", (string)null); + }); + + modelBuilder.Entity("LINGYUN.Abp.TaskManagement.BackgroundJobLog", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("bigint"); + + b.Property("Exception") + .HasMaxLength(2000) + .HasColumnType("varchar(2000)") + .HasColumnName("Exception"); + + b.Property("JobGroup") + .HasMaxLength(50) + .HasColumnType("varchar(50)") + .HasColumnName("JobGroup"); + + b.Property("JobId") + .HasMaxLength(255) + .HasColumnType("varchar(255)") + .HasColumnName("JobId"); + + b.Property("JobName") + .HasMaxLength(100) + .HasColumnType("varchar(100)") + .HasColumnName("JobName"); + + b.Property("JobType") + .HasMaxLength(1000) + .HasColumnType("varchar(1000)") + .HasColumnName("JobType"); + + b.Property("Message") + .HasMaxLength(1000) + .HasColumnType("varchar(1000)") + .HasColumnName("Message"); + + b.Property("RunTime") + .HasColumnType("datetime(6)"); + + b.Property("TenantId") + .HasColumnType("char(36)") + .HasColumnName("TenantId"); + + b.HasKey("Id"); + + b.HasIndex("JobGroup", "JobName"); + + b.ToTable("TK_BackgroundJobLogs", (string)null); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/aspnet-core/services/LY.MicroService.TaskManagement.HttpApi.Host/Migrations/20220330013146_Add-Field-Source-With-BackgroundJobInfo.cs b/aspnet-core/services/LY.MicroService.TaskManagement.HttpApi.Host/Migrations/20220330013146_Add-Field-Source-With-BackgroundJobInfo.cs new file mode 100644 index 000000000..a5b4204ec --- /dev/null +++ b/aspnet-core/services/LY.MicroService.TaskManagement.HttpApi.Host/Migrations/20220330013146_Add-Field-Source-With-BackgroundJobInfo.cs @@ -0,0 +1,26 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace LY.MicroService.TaskManagement.Migrations +{ + public partial class AddFieldSourceWithBackgroundJobInfo : Migration + { + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.AddColumn( + name: "Source", + table: "TK_BackgroundJobs", + type: "int", + nullable: false, + defaultValue: -1); + } + + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropColumn( + name: "Source", + table: "TK_BackgroundJobs"); + } + } +} diff --git a/aspnet-core/services/LY.MicroService.TaskManagement.HttpApi.Host/Migrations/TaskManagementMigrationsDbContextModelSnapshot.cs b/aspnet-core/services/LY.MicroService.TaskManagement.HttpApi.Host/Migrations/TaskManagementMigrationsDbContextModelSnapshot.cs index aba69c5a2..1b6f44954 100644 --- a/aspnet-core/services/LY.MicroService.TaskManagement.HttpApi.Host/Migrations/TaskManagementMigrationsDbContextModelSnapshot.cs +++ b/aspnet-core/services/LY.MicroService.TaskManagement.HttpApi.Host/Migrations/TaskManagementMigrationsDbContextModelSnapshot.cs @@ -18,7 +18,7 @@ namespace LY.MicroService.TaskManagement.Migrations #pragma warning disable 612, 618 modelBuilder .HasAnnotation("_Abp_DatabaseProvider", EfCoreDatabaseProvider.MySql) - .HasAnnotation("ProductVersion", "6.0.1") + .HasAnnotation("ProductVersion", "6.0.3") .HasAnnotation("Relational:MaxIdentifierLength", 64); modelBuilder.Entity("LINGYUN.Abp.TaskManagement.BackgroundJobInfo", b => @@ -119,6 +119,12 @@ namespace LY.MicroService.TaskManagement.Migrations .HasColumnType("varchar(1000)") .HasColumnName("Result"); + b.Property("Source") + .ValueGeneratedOnAdd() + .HasColumnType("int") + .HasDefaultValue(-1) + .HasColumnName("Source"); + b.Property("Status") .HasColumnType("int");