diff --git a/aspnet-core/modules/workflow/LINGYUN.Abp.WorkflowCore.Persistence.EntityFrameworkCore/LINGYUN/Abp/WorkflowCore/Persistence/EntityFrameworkCore/EfCoreRepositoryExtensions.cs b/aspnet-core/modules/workflow/LINGYUN.Abp.WorkflowCore.Persistence.EntityFrameworkCore/LINGYUN/Abp/WorkflowCore/Persistence/EntityFrameworkCore/EfCoreRepositoryExtensions.cs new file mode 100644 index 000000000..4bae00f7c --- /dev/null +++ b/aspnet-core/modules/workflow/LINGYUN.Abp.WorkflowCore.Persistence.EntityFrameworkCore/LINGYUN/Abp/WorkflowCore/Persistence/EntityFrameworkCore/EfCoreRepositoryExtensions.cs @@ -0,0 +1,18 @@ +using Microsoft.EntityFrameworkCore; +using System.Linq; + +namespace LINGYUN.Abp.WorkflowCore.Persistence.EntityFrameworkCore +{ + public static class EfCoreRepositoryExtensions + { + public static IQueryable IncludeIf( + this IQueryable quertable, + bool includeDetails = true) + { + return !includeDetails ? quertable : + quertable + .Include(x => x.ExecutionPointers) + .ThenInclude(p => p.ExtensionAttributes); + } + } +} diff --git a/aspnet-core/modules/workflow/LINGYUN.Abp.WorkflowCore.Persistence.EntityFrameworkCore/LINGYUN/Abp/WorkflowCore/Persistence/EntityFrameworkCore/EfCoreWorkflowRepository.cs b/aspnet-core/modules/workflow/LINGYUN.Abp.WorkflowCore.Persistence.EntityFrameworkCore/LINGYUN/Abp/WorkflowCore/Persistence/EntityFrameworkCore/EfCoreWorkflowRepository.cs index 8885f1375..bbc2f4b8a 100644 --- a/aspnet-core/modules/workflow/LINGYUN.Abp.WorkflowCore.Persistence.EntityFrameworkCore/LINGYUN/Abp/WorkflowCore/Persistence/EntityFrameworkCore/EfCoreWorkflowRepository.cs +++ b/aspnet-core/modules/workflow/LINGYUN.Abp.WorkflowCore.Persistence.EntityFrameworkCore/LINGYUN/Abp/WorkflowCore/Persistence/EntityFrameworkCore/EfCoreWorkflowRepository.cs @@ -27,8 +27,7 @@ namespace LINGYUN.Abp.WorkflowCore.Persistence int take, CancellationToken cancellationToken = default) { - return await (await GetDbSetAsync()) - .Include(x => x.ExecutionPointers) + return await (await WithDetailsAsync()) .WhereIf(status.HasValue, x => x.Status == status.Value) .WhereIf(!type.IsNullOrWhiteSpace(), x => x.WorkflowDefinitionId.Equals(type)) .WhereIf(createdFrom.HasValue, x => x.CreationTime >= createdFrom.Value) @@ -37,12 +36,22 @@ namespace LINGYUN.Abp.WorkflowCore.Persistence .ToListAsync(); } + public virtual async Task> GetOlderListAsync( + WorkflowStatus status, + DateTime olderThan, + bool includeDetails = false, + int? maxResultCount = null, + CancellationToken cancellationToken = default) + { + return await (await WithDetailsAsync()) + .Where(x => x.Status == status && x.CompleteTime < olderThan) + .ToListAsync(); + } + public override async Task> WithDetailsAsync() { var quertable = await base.WithDetailsAsync(); - return quertable - .Include(x => x.ExecutionPointers) - .ThenInclude(p => p.ExtensionAttributes); + return quertable.IncludeIf(true); } } } diff --git a/aspnet-core/modules/workflow/LINGYUN.Abp.WorkflowCore.Persistence/LINGYUN/Abp/WorkflowCore/Persistence/AbpWorkflowCorePersistenceModule.cs b/aspnet-core/modules/workflow/LINGYUN.Abp.WorkflowCore.Persistence/LINGYUN/Abp/WorkflowCore/Persistence/AbpWorkflowCorePersistenceModule.cs index f2a887a25..97f0724d0 100644 --- a/aspnet-core/modules/workflow/LINGYUN.Abp.WorkflowCore.Persistence/LINGYUN/Abp/WorkflowCore/Persistence/AbpWorkflowCorePersistenceModule.cs +++ b/aspnet-core/modules/workflow/LINGYUN.Abp.WorkflowCore.Persistence/LINGYUN/Abp/WorkflowCore/Persistence/AbpWorkflowCorePersistenceModule.cs @@ -10,6 +10,7 @@ namespace LINGYUN.Abp.WorkflowCore.Persistence { public override void PreConfigureServices(ServiceConfigurationContext context) { + context.Services.AddTransient(); context.Services.AddTransient(); context.Services.AddTransient(); diff --git a/aspnet-core/modules/workflow/LINGYUN.Abp.WorkflowCore.Persistence/LINGYUN/Abp/WorkflowCore/Persistence/AbpWorkflowPurger.cs b/aspnet-core/modules/workflow/LINGYUN.Abp.WorkflowCore.Persistence/LINGYUN/Abp/WorkflowCore/Persistence/AbpWorkflowPurger.cs new file mode 100644 index 000000000..d0c18904b --- /dev/null +++ b/aspnet-core/modules/workflow/LINGYUN.Abp.WorkflowCore.Persistence/LINGYUN/Abp/WorkflowCore/Persistence/AbpWorkflowPurger.cs @@ -0,0 +1,28 @@ +using System; +using System.Threading.Tasks; +using WorkflowCore.Interface; +using WorkflowCore.Models; + +namespace LINGYUN.Abp.WorkflowCore.Persistence +{ + public class AbpWorkflowPurger : IWorkflowPurger + { + private readonly IWorkflowRepository _workflowRepository; + + public AbpWorkflowPurger( + IWorkflowRepository workflowRepository) + { + _workflowRepository = workflowRepository; + } + + public virtual async Task PurgeWorkflows(WorkflowStatus status, DateTime olderThan) + { + var olderThanUtc = olderThan.ToUniversalTime(); + + var workflows = await _workflowRepository + .GetOlderListAsync(status, olderThanUtc, includeDetails: true); + + await _workflowRepository.DeleteManyAsync(workflows); + } + } +} diff --git a/aspnet-core/modules/workflow/LINGYUN.Abp.WorkflowCore.Persistence/LINGYUN/Abp/WorkflowCore/Persistence/IWorkflowRepository.cs b/aspnet-core/modules/workflow/LINGYUN.Abp.WorkflowCore.Persistence/LINGYUN/Abp/WorkflowCore/Persistence/IWorkflowRepository.cs index 1025baaba..e2d7ed969 100644 --- a/aspnet-core/modules/workflow/LINGYUN.Abp.WorkflowCore.Persistence/LINGYUN/Abp/WorkflowCore/Persistence/IWorkflowRepository.cs +++ b/aspnet-core/modules/workflow/LINGYUN.Abp.WorkflowCore.Persistence/LINGYUN/Abp/WorkflowCore/Persistence/IWorkflowRepository.cs @@ -17,5 +17,12 @@ namespace LINGYUN.Abp.WorkflowCore.Persistence int skip, int take, CancellationToken cancellationToken = default); + + Task> GetOlderListAsync( + WorkflowStatus status, + DateTime olderThan, + bool includeDetails = false, + int? maxResultCount = null, + CancellationToken cancellationToken = default); } } diff --git a/aspnet-core/modules/workflow/LINGYUN.Abp.WorkflowCore.Persistence/LINGYUN/Abp/WorkflowCore/Persistence/PersistedWorkflow.cs b/aspnet-core/modules/workflow/LINGYUN.Abp.WorkflowCore.Persistence/LINGYUN/Abp/WorkflowCore/Persistence/PersistedWorkflow.cs index 3c6331f0c..098b2b5ad 100644 --- a/aspnet-core/modules/workflow/LINGYUN.Abp.WorkflowCore.Persistence/LINGYUN/Abp/WorkflowCore/Persistence/PersistedWorkflow.cs +++ b/aspnet-core/modules/workflow/LINGYUN.Abp.WorkflowCore.Persistence/LINGYUN/Abp/WorkflowCore/Persistence/PersistedWorkflow.cs @@ -1,7 +1,9 @@ -using System; +using JetBrains.Annotations; +using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Linq; +using Volo.Abp; using Volo.Abp.Domain.Entities.Auditing; using Volo.Abp.MultiTenancy; using WorkflowCore.Models; @@ -53,8 +55,10 @@ namespace LINGYUN.Abp.WorkflowCore.Persistence ExecutionPointers = new Collection(); } - public void AddPointer(PersistedExecutionPointer pointer) + public void AddPointer([NotNull] PersistedExecutionPointer pointer) { + Check.NotNull(pointer, nameof(pointer)); + ExecutionPointers.Add(pointer); } @@ -62,5 +66,22 @@ namespace LINGYUN.Abp.WorkflowCore.Persistence { return ExecutionPointers.FirstOrDefault(point => point.Id.Equals(id)); } + + public void RemovePointers([NotNull] IEnumerable pointers) + { + Check.NotNull(pointers, nameof(pointers)); + + foreach (var pointer in pointers) + { + RemovePointer(pointer); + } + } + + public virtual void RemovePointer([NotNull] PersistedExecutionPointer pointer) + { + Check.NotNull(pointer, nameof(pointer)); + + ExecutionPointers.RemoveAll(c => c.Id == pointer.Id); + } } } diff --git a/aspnet-core/modules/workflow/LINGYUN.Abp.WorkflowManagement.Application.Contracts/LINGYUN/Abp/WorkflowManagement/Authorization/WorkflowManagementPermissionDefinitionProvider.cs b/aspnet-core/modules/workflow/LINGYUN.Abp.WorkflowManagement.Application.Contracts/LINGYUN/Abp/WorkflowManagement/Authorization/WorkflowManagementPermissionDefinitionProvider.cs index b763b1a32..7f3c6344d 100644 --- a/aspnet-core/modules/workflow/LINGYUN.Abp.WorkflowManagement.Application.Contracts/LINGYUN/Abp/WorkflowManagement/Authorization/WorkflowManagementPermissionDefinitionProvider.cs +++ b/aspnet-core/modules/workflow/LINGYUN.Abp.WorkflowManagement.Application.Contracts/LINGYUN/Abp/WorkflowManagement/Authorization/WorkflowManagementPermissionDefinitionProvider.cs @@ -16,6 +16,9 @@ namespace LINGYUN.Abp.WorkflowManagement.Authorization engine.AddChild( WorkflowManagementPermissions.Engine.Initialize, L("Permission:Initialize")); + engine.AddChild( + WorkflowManagementPermissions.Engine.Register, + L("Permission:Register")); var workflow = group.AddPermission( WorkflowManagementPermissions.WorkflowDef.Default, diff --git a/aspnet-core/modules/workflow/LINGYUN.Abp.WorkflowManagement.Application.Contracts/LINGYUN/Abp/WorkflowManagement/Authorization/WorkflowManagementPermissions.cs b/aspnet-core/modules/workflow/LINGYUN.Abp.WorkflowManagement.Application.Contracts/LINGYUN/Abp/WorkflowManagement/Authorization/WorkflowManagementPermissions.cs index 44c090cde..de9ee2765 100644 --- a/aspnet-core/modules/workflow/LINGYUN.Abp.WorkflowManagement.Application.Contracts/LINGYUN/Abp/WorkflowManagement/Authorization/WorkflowManagementPermissions.cs +++ b/aspnet-core/modules/workflow/LINGYUN.Abp.WorkflowManagement.Application.Contracts/LINGYUN/Abp/WorkflowManagement/Authorization/WorkflowManagementPermissions.cs @@ -11,6 +11,8 @@ public const string Default = GroupName + ".Engine"; public const string Initialize = Default + ".Initialize"; + + public const string Register = Default + ".Register"; } public static class WorkflowDef diff --git a/aspnet-core/modules/workflow/LINGYUN.Abp.WorkflowManagement.Application.Contracts/LINGYUN/Abp/WorkflowManagement/Engine/IEngineAppService.cs b/aspnet-core/modules/workflow/LINGYUN.Abp.WorkflowManagement.Application.Contracts/LINGYUN/Abp/WorkflowManagement/Engine/IEngineAppService.cs index 93e901fc1..a6e60297f 100644 --- a/aspnet-core/modules/workflow/LINGYUN.Abp.WorkflowManagement.Application.Contracts/LINGYUN/Abp/WorkflowManagement/Engine/IEngineAppService.cs +++ b/aspnet-core/modules/workflow/LINGYUN.Abp.WorkflowManagement.Application.Contracts/LINGYUN/Abp/WorkflowManagement/Engine/IEngineAppService.cs @@ -6,5 +6,7 @@ namespace LINGYUN.Abp.WorkflowManagement.Engine public interface IEngineAppService : IApplicationService { Task InitializeAsync(); + + Task RegisterAsync(); } } diff --git a/aspnet-core/modules/workflow/LINGYUN.Abp.WorkflowManagement.Application/LINGYUN/Abp/WorkflowManagement/Engine/EngineAppService.cs b/aspnet-core/modules/workflow/LINGYUN.Abp.WorkflowManagement.Application/LINGYUN/Abp/WorkflowManagement/Engine/EngineAppService.cs index eef5b83a7..0a2cc6bbf 100644 --- a/aspnet-core/modules/workflow/LINGYUN.Abp.WorkflowManagement.Application/LINGYUN/Abp/WorkflowManagement/Engine/EngineAppService.cs +++ b/aspnet-core/modules/workflow/LINGYUN.Abp.WorkflowManagement.Application/LINGYUN/Abp/WorkflowManagement/Engine/EngineAppService.cs @@ -8,10 +8,14 @@ namespace LINGYUN.Abp.WorkflowManagement.Engine public class EngineAppService : WorkflowManagementAppServiceBase, IEngineAppService { private readonly IWorkflowEngineManager _engineManager; + private readonly IWorkflowRegistryManager _registryManager; - public EngineAppService(IWorkflowEngineManager engineManager) + public EngineAppService( + IWorkflowEngineManager engineManager, + IWorkflowRegistryManager registryManager) { _engineManager = engineManager; + _registryManager = registryManager; } [Authorize(WorkflowManagementPermissions.Engine.Initialize)] @@ -19,5 +23,12 @@ namespace LINGYUN.Abp.WorkflowManagement.Engine { await _engineManager.InitializeAsync(); } + + [Authorize(WorkflowManagementPermissions.Engine.Register)] + public virtual async Task RegisterAsync() + { + // 暂时没有解决多租户自动注册工作流,管理员可以通过api主动注册 + await _registryManager.RegisterAsync(); + } } } diff --git a/aspnet-core/modules/workflow/LINGYUN.Abp.WorkflowManagement.Domain.Shared/LINGYUN/Abp/WorkflowManagement/Localization/Resources/en.json b/aspnet-core/modules/workflow/LINGYUN.Abp.WorkflowManagement.Domain.Shared/LINGYUN/Abp/WorkflowManagement/Localization/Resources/en.json index f986379a3..aa07505ee 100644 --- a/aspnet-core/modules/workflow/LINGYUN.Abp.WorkflowManagement.Domain.Shared/LINGYUN/Abp/WorkflowManagement/Localization/Resources/en.json +++ b/aspnet-core/modules/workflow/LINGYUN.Abp.WorkflowManagement.Domain.Shared/LINGYUN/Abp/WorkflowManagement/Localization/Resources/en.json @@ -4,6 +4,7 @@ "Permission:WorkflowManagement": "WorkflowManagement", "Permission:Engine": "Engine", "Permission:Initialize": "Initialize", + "Permission:Register": "Register", "Permission:WorkflowDef": "Definition", "Permission:Create": "Create", "Permission:Delete": "Delete", diff --git a/aspnet-core/modules/workflow/LINGYUN.Abp.WorkflowManagement.Domain.Shared/LINGYUN/Abp/WorkflowManagement/Localization/Resources/zh-Hans.json b/aspnet-core/modules/workflow/LINGYUN.Abp.WorkflowManagement.Domain.Shared/LINGYUN/Abp/WorkflowManagement/Localization/Resources/zh-Hans.json index 4744c7e59..2a74d4086 100644 --- a/aspnet-core/modules/workflow/LINGYUN.Abp.WorkflowManagement.Domain.Shared/LINGYUN/Abp/WorkflowManagement/Localization/Resources/zh-Hans.json +++ b/aspnet-core/modules/workflow/LINGYUN.Abp.WorkflowManagement.Domain.Shared/LINGYUN/Abp/WorkflowManagement/Localization/Resources/zh-Hans.json @@ -4,6 +4,7 @@ "Permission:WorkflowManagement": "工作流管理", "Permission:Engine": "流程引擎", "Permission:Initialize": "初始化", + "Permission:Register": "注册组件", "Permission:WorkflowDef": "流程定义", "Permission:Create": "创建", "Permission:Delete": "删除", diff --git a/aspnet-core/modules/workflow/LINGYUN.Abp.WorkflowManagement.Domain/LINGYUN/Abp/WorkflowManagement/IWorkflowRegistryManager.cs b/aspnet-core/modules/workflow/LINGYUN.Abp.WorkflowManagement.Domain/LINGYUN/Abp/WorkflowManagement/IWorkflowRegistryManager.cs new file mode 100644 index 000000000..c6c174b36 --- /dev/null +++ b/aspnet-core/modules/workflow/LINGYUN.Abp.WorkflowManagement.Domain/LINGYUN/Abp/WorkflowManagement/IWorkflowRegistryManager.cs @@ -0,0 +1,10 @@ +using System.Threading; +using System.Threading.Tasks; + +namespace LINGYUN.Abp.WorkflowManagement +{ + public interface IWorkflowRegistryManager + { + Task RegisterAsync(CancellationToken cancellationToken = default); + } +} diff --git a/aspnet-core/modules/workflow/LINGYUN.Abp.WorkflowManagement.Domain/LINGYUN/Abp/WorkflowManagement/WorkflowManager.cs b/aspnet-core/modules/workflow/LINGYUN.Abp.WorkflowManagement.Domain/LINGYUN/Abp/WorkflowManagement/WorkflowManager.cs index 65b60a6b4..e6971dc72 100644 --- a/aspnet-core/modules/workflow/LINGYUN.Abp.WorkflowManagement.Domain/LINGYUN/Abp/WorkflowManagement/WorkflowManager.cs +++ b/aspnet-core/modules/workflow/LINGYUN.Abp.WorkflowManagement.Domain/LINGYUN/Abp/WorkflowManagement/WorkflowManager.cs @@ -19,19 +19,20 @@ namespace LINGYUN.Abp.WorkflowManagement public class WorkflowManager : DomainService, ITransientDependency { private readonly IWorkflowRegistry _registry; - private readonly IPersistenceProvider _persistenceProvider; - public WorkflowManager( - IWorkflowRegistry registry, - IPersistenceProvider persistenceProvider) + public WorkflowManager(IWorkflowRegistry registry) { _registry = registry; - _persistenceProvider = persistenceProvider; + } + + public virtual bool IsRegistered(Workflow workflow) + { + return _registry.IsRegistered(workflow.Id.ToString(), workflow.Version); } public virtual void UnRegister(Workflow workflow) { - if (_registry.IsRegistered(workflow.Id.ToString(), workflow.Version)) + if (IsRegistered(workflow)) { _registry.DeregisterWorkflow(workflow.Id.ToString(), workflow.Version); } @@ -42,22 +43,28 @@ namespace LINGYUN.Abp.WorkflowManagement ICollection steps, ICollection compensates) { - var dataType = typeof(Dictionary); - var source = new DefinitionSourceV1 + if (!IsRegistered(workflow)) { - Id = workflow.Id.ToString(), - Version = workflow.Version, - Description = workflow.Description ?? workflow.DisplayName, - DataType = $"{dataType.FullName}, {dataType.Assembly}", - DefaultErrorBehavior = workflow.ErrorBehavior, - DefaultErrorRetryInterval = workflow.ErrorRetryInterval, - Steps = ConvertSteps(steps, compensates) - }; + var dataType = typeof(Dictionary); + var source = new DefinitionSourceV1 + { + Id = workflow.Id.ToString(), + Version = workflow.Version, + Description = workflow.Description ?? workflow.DisplayName, + DataType = $"{dataType.FullName}, {dataType.Assembly}", + DefaultErrorBehavior = workflow.ErrorBehavior, + DefaultErrorRetryInterval = workflow.ErrorRetryInterval, + Steps = ConvertSteps(steps, compensates) + }; + + var def = Convert(source); - var def = Convert(source); - _registry.RegisterWorkflow(def); + _registry.RegisterWorkflow(def); + + return def; + } - return def; + return _registry.GetDefinition(workflow.Id.ToString(), workflow.Version); } private List ConvertSteps( diff --git a/aspnet-core/modules/workflow/LINGYUN.Abp.WorkflowManagement.Domain/LINGYUN/Abp/WorkflowManagement/WorkflowRegisterService.cs b/aspnet-core/modules/workflow/LINGYUN.Abp.WorkflowManagement.Domain/LINGYUN/Abp/WorkflowManagement/WorkflowRegisterService.cs index 85e34d799..0869e8f4a 100644 --- a/aspnet-core/modules/workflow/LINGYUN.Abp.WorkflowManagement.Domain/LINGYUN/Abp/WorkflowManagement/WorkflowRegisterService.cs +++ b/aspnet-core/modules/workflow/LINGYUN.Abp.WorkflowManagement.Domain/LINGYUN/Abp/WorkflowManagement/WorkflowRegisterService.cs @@ -6,35 +6,17 @@ namespace LINGYUN.Abp.WorkflowManagement { public class WorkflowRegisterService : BackgroundService { - private readonly WorkflowManager _workflowManager; - - private readonly IWorkflowRepository _workflowRepository; - private readonly IStepNodeRepository _stepNodeRepository; - private readonly ICompensateNodeRepository _compensateNodeRepository; + private readonly IWorkflowRegistryManager _registryManager; public WorkflowRegisterService( - WorkflowManager workflowManager, - IWorkflowRepository workflowRepository, - IStepNodeRepository stepNodeRepository, - ICompensateNodeRepository compensateNodeRepository) + IWorkflowRegistryManager registryManager) { - _workflowManager = workflowManager; - _workflowRepository = workflowRepository; - _stepNodeRepository = stepNodeRepository; - _compensateNodeRepository = compensateNodeRepository; + _registryManager = registryManager; } protected override async Task ExecuteAsync(CancellationToken stoppingToken) { - var workflows = await _workflowRepository.GetListAsync(x => x.IsEnabled, cancellationToken: stoppingToken); - - foreach (var workflow in workflows) - { - var stepNodes = await _stepNodeRepository.GetAllChildrenWithWorkflowAsync(workflow.Id, cancellationToken: stoppingToken); - var compensateNodes = await _compensateNodeRepository.GetAllChildrenWithWorkflowAsync(workflow.Id, cancellationToken: stoppingToken); - - _workflowManager.Register(workflow, stepNodes, compensateNodes); - } + await _registryManager.RegisterAsync(stoppingToken); } } } diff --git a/aspnet-core/modules/workflow/LINGYUN.Abp.WorkflowManagement.Domain/LINGYUN/Abp/WorkflowManagement/WorkflowRegistryManager.cs b/aspnet-core/modules/workflow/LINGYUN.Abp.WorkflowManagement.Domain/LINGYUN/Abp/WorkflowManagement/WorkflowRegistryManager.cs new file mode 100644 index 000000000..6e0c0ffc8 --- /dev/null +++ b/aspnet-core/modules/workflow/LINGYUN.Abp.WorkflowManagement.Domain/LINGYUN/Abp/WorkflowManagement/WorkflowRegistryManager.cs @@ -0,0 +1,48 @@ +using System.Threading; +using System.Threading.Tasks; +using Volo.Abp.DependencyInjection; + +namespace LINGYUN.Abp.WorkflowManagement +{ + public class WorkflowRegistryManager : IWorkflowRegistryManager, ITransientDependency + { + private readonly WorkflowManager _workflowManager; + + private readonly IWorkflowRepository _workflowRepository; + private readonly IStepNodeRepository _stepNodeRepository; + private readonly ICompensateNodeRepository _compensateNodeRepository; + + public WorkflowRegistryManager( + WorkflowManager workflowManager, + IWorkflowRepository workflowRepository, + IStepNodeRepository stepNodeRepository, + ICompensateNodeRepository compensateNodeRepository) + { + _workflowManager = workflowManager; + _workflowRepository = workflowRepository; + _stepNodeRepository = stepNodeRepository; + _compensateNodeRepository = compensateNodeRepository; + } + + public virtual async Task RegisterAsync(CancellationToken cancellationToken = default) + { + // TODO: 多租户如何注册? + + var workflows = await _workflowRepository + .GetListAsync(x => x.IsEnabled, cancellationToken: cancellationToken); + + foreach (var workflow in workflows) + { + if (!_workflowManager.IsRegistered(workflow)) + { + var stepNodes = await _stepNodeRepository + .GetAllChildrenWithWorkflowAsync(workflow.Id, cancellationToken: cancellationToken); + var compensateNodes = await _compensateNodeRepository + .GetAllChildrenWithWorkflowAsync(workflow.Id, cancellationToken: cancellationToken); + + _workflowManager.Register(workflow, stepNodes, compensateNodes); + } + } + } + } +} diff --git a/aspnet-core/modules/workflow/LINGYUN.Abp.WorkflowManagement.HttpApi/LINGYUN/Abp/WorkflowManagement/Engine/EngineController.cs b/aspnet-core/modules/workflow/LINGYUN.Abp.WorkflowManagement.HttpApi/LINGYUN/Abp/WorkflowManagement/Engine/EngineController.cs index 0bc7d4b62..cf6c9727c 100644 --- a/aspnet-core/modules/workflow/LINGYUN.Abp.WorkflowManagement.HttpApi/LINGYUN/Abp/WorkflowManagement/Engine/EngineController.cs +++ b/aspnet-core/modules/workflow/LINGYUN.Abp.WorkflowManagement.HttpApi/LINGYUN/Abp/WorkflowManagement/Engine/EngineController.cs @@ -23,5 +23,12 @@ namespace LINGYUN.Abp.WorkflowManagement.Engine { await _service.InitializeAsync(); } + + [HttpPost] + [Route("register")] + public virtual async Task RegisterAsync() + { + await _service.RegisterAsync(); + } } } diff --git a/aspnet-core/services/LY.MicroService.WorkflowManagement.HttpApi.Host/WorkflowEngineManager.cs b/aspnet-core/services/LY.MicroService.WorkflowManagement.HttpApi.Host/WorkflowEngineManager.cs index c64cc7f08..1d1962f44 100644 --- a/aspnet-core/services/LY.MicroService.WorkflowManagement.HttpApi.Host/WorkflowEngineManager.cs +++ b/aspnet-core/services/LY.MicroService.WorkflowManagement.HttpApi.Host/WorkflowEngineManager.cs @@ -15,6 +15,7 @@ public class WorkflowEngineManager : IWorkflowEngineManager, ISingletonDependenc { private readonly IWorkflowHost _workflowHost; private readonly IDbSchemaMigrator _dbSchemaMigrator; + private readonly ILogger _logger; public WorkflowEngineManager( IWorkflowHost workflowHost, @@ -49,6 +50,11 @@ public class WorkflowEngineManager : IWorkflowEngineManager, ISingletonDependenc _logger.LogInformation("Migrated workflow management context."); } + public async Task RegisterAsync(CancellationToken cancellationToken = default) + { + + } + public async Task StartAsync(CancellationToken cancellationToken = default) { await _workflowHost.StartAsync(cancellationToken);