-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #118 from jxnkwlp/feature/cleanup
🚀 Support automatic cleanup of workflow instance data #117
- Loading branch information
Showing
46 changed files
with
1,581 additions
and
102 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
src/Passingwind.Abp.ElsaModule.Application.Contracts/Settings/CleanupSettingsDto.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
namespace Passingwind.Abp.ElsaModule.Settings; | ||
|
||
public class CleanupSettingsDto | ||
{ | ||
public bool Enabled { get; set; } | ||
public int KeepDays { get; set; } | ||
public bool ScopeAll { get; set; } | ||
public int[] Scopes { get; set; } | ||
} |
10 changes: 10 additions & 0 deletions
10
src/Passingwind.Abp.ElsaModule.Application.Contracts/Settings/IWorkflowSettingsAppService.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
using System.Threading.Tasks; | ||
using Volo.Abp.Application.Services; | ||
|
||
namespace Passingwind.Abp.ElsaModule.Settings; | ||
|
||
public interface IWorkflowSettingsAppService : IApplicationService | ||
{ | ||
Task<CleanupSettingsDto> GetCleanupAsync(); | ||
Task UpdateCleanupAsync(CleanupSettingsDto input); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
src/Passingwind.Abp.ElsaModule.Application/Settings/WorkflowSettingsAppService.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
using System; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
using Microsoft.AspNetCore.Authorization; | ||
using Passingwind.Abp.ElsaModule.Cleanup; | ||
using Passingwind.Abp.ElsaModule.Common; | ||
using Passingwind.Abp.ElsaModule.Permissions; | ||
|
||
namespace Passingwind.Abp.ElsaModule.Settings; | ||
|
||
[Authorize(ElsaModulePermissions.Settings.Default)] | ||
public class WorkflowSettingsAppService : ElsaModuleAppService, IWorkflowSettingsAppService | ||
{ | ||
protected ICleanupSettingsManager CleanupSettingsManager { get; } | ||
|
||
public WorkflowSettingsAppService(ICleanupSettingsManager cleanupSettingsManager) | ||
{ | ||
CleanupSettingsManager = cleanupSettingsManager; | ||
} | ||
|
||
[Authorize(ElsaModulePermissions.Settings.InstanceCleanup)] | ||
public virtual async Task<CleanupSettingsDto> GetCleanupAsync() | ||
{ | ||
var settings = await CleanupSettingsManager.GetAsync(); | ||
|
||
var scopes = settings.Scopes; | ||
|
||
return new CleanupSettingsDto() | ||
{ | ||
Enabled = settings.Enabled, | ||
KeepDays = settings.KeepDays, | ||
ScopeAll = scopes.HasFlag(WorkflowInstanceCleanupScope.All), | ||
Scopes = Enum.GetValues<WorkflowInstanceCleanupScope>().Cast<WorkflowInstanceCleanupScope>().Where(x => scopes.HasFlag(x)).Cast<int>().ToArray(), | ||
}; | ||
} | ||
|
||
[Authorize(ElsaModulePermissions.Settings.InstanceCleanup)] | ||
public virtual async Task UpdateCleanupAsync(CleanupSettingsDto input) | ||
{ | ||
await CleanupSettingsManager.UpdateAsync(new CleanupSettings | ||
{ | ||
Enabled = input.Enabled, | ||
KeepDays = input.KeepDays, | ||
Scopes = input.ScopeAll ? WorkflowInstanceCleanupScope.All : (WorkflowInstanceCleanupScope)input.Scopes.Sum(), | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
src/Passingwind.Abp.ElsaModule.Domain.Shared/Common/WorkflowInstanceCleanupScope.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
using System; | ||
|
||
namespace Passingwind.Abp.ElsaModule.Common; | ||
|
||
[Flags] | ||
public enum WorkflowInstanceCleanupScope | ||
{ | ||
None = 0, | ||
Input = 1, | ||
Output = 1 << 1, | ||
Faults = 1 << 2, | ||
Variables = 1 << 3, | ||
Metadata = 1 << 4, | ||
ActivityScopes = 1 << 5, | ||
ActivityData = 1 << 6, | ||
ExecutionLogs = 1 << 7, | ||
All = 1 << 16, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
src/Passingwind.Abp.ElsaModule.Domain/Cleanup/CleanupBackgroundWorker.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
using System; | ||
using System.Threading.Tasks; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Microsoft.Extensions.Logging; | ||
using Volo.Abp.BackgroundWorkers; | ||
using Volo.Abp.DependencyInjection; | ||
using Volo.Abp.Threading; | ||
|
||
namespace Passingwind.Abp.ElsaModule.Cleanup; | ||
|
||
public class CleanupBackgroundWorker : AsyncPeriodicBackgroundWorkerBase, ITransientDependency | ||
{ | ||
public CleanupBackgroundWorker(AbpAsyncTimer timer, IServiceScopeFactory serviceScopeFactory) : base(timer, serviceScopeFactory) | ||
{ | ||
timer.Period = (int)TimeSpan.FromHours(6).TotalMilliseconds; | ||
} | ||
|
||
protected override async Task DoWorkAsync(PeriodicBackgroundWorkerContext workerContext) | ||
{ | ||
var service = workerContext.ServiceProvider.GetRequiredService<ICleanupRunner>(); | ||
|
||
try | ||
{ | ||
await service.RunAsync(); | ||
} | ||
catch (Exception ex) | ||
{ | ||
Logger.LogError(ex, "Executing workflow instance cleanup job failed."); | ||
} | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
src/Passingwind.Abp.ElsaModule.Domain/Cleanup/CleanupRunner.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using Microsoft.Extensions.Logging; | ||
using Volo.Abp.DependencyInjection; | ||
using Volo.Abp.Timing; | ||
|
||
namespace Passingwind.Abp.ElsaModule.Cleanup; | ||
|
||
public class CleanupRunner : ICleanupRunner, IScopedDependency | ||
{ | ||
protected ILogger<CleanupRunner> Logger { get; } | ||
protected IClock Clock { get; } | ||
protected ICleanupSettingsManager CleanupSettingsManager { get; } | ||
protected IWorkflowInstanceCleanupProvider InstanceCleanupProvider { get; } | ||
|
||
public CleanupRunner(ILogger<CleanupRunner> logger, IClock clock, ICleanupSettingsManager cleanupSettingsManager, IWorkflowInstanceCleanupProvider instanceCleanupProvider) | ||
{ | ||
Logger = logger; | ||
Clock = clock; | ||
CleanupSettingsManager = cleanupSettingsManager; | ||
InstanceCleanupProvider = instanceCleanupProvider; | ||
} | ||
|
||
public virtual async Task RunAsync(bool fource = false, CancellationToken cancellationToken = default) | ||
{ | ||
var settings = await CleanupSettingsManager.GetAsync(cancellationToken); | ||
|
||
if (!settings.Enabled && !fource) | ||
{ | ||
Logger.LogDebug("Cleanup settings are not enabled."); | ||
return; | ||
} | ||
|
||
var endDate = Clock.Now.Date.AddDays(-settings.KeepDays); | ||
|
||
await InstanceCleanupProvider.ExecutingAsync(endDate, settings.Scopes, cancellationToken); | ||
} | ||
} |
Oops, something went wrong.