| | | 1 | | using Elsa.Alterations.Core.Contracts; |
| | | 2 | | using Elsa.Alterations.Core.Entities; |
| | | 3 | | using Elsa.Alterations.Core.Enums; |
| | | 4 | | using Elsa.Alterations.Core.Filters; |
| | | 5 | | using Elsa.Alterations.Core.Notifications; |
| | | 6 | | using Elsa.Common; |
| | | 7 | | using Elsa.Mediator.Contracts; |
| | | 8 | | |
| | | 9 | | namespace Elsa.Alterations.Services; |
| | | 10 | | |
| | | 11 | | /// <inheritdoc /> |
| | 320 | 12 | | public class AlterationPlanManager(IAlterationPlanStore planStore, IAlterationJobStore jobStore, ISystemClock systemCloc |
| | | 13 | | { |
| | | 14 | | /// <inheritdoc /> |
| | | 15 | | public async Task<AlterationPlan?> GetPlanAsync(string planId, CancellationToken cancellationToken = default) |
| | | 16 | | { |
| | 0 | 17 | | var planFilter = new AlterationPlanFilter { Id = planId }; |
| | 0 | 18 | | return await planStore.FindAsync(planFilter, cancellationToken); |
| | 0 | 19 | | } |
| | | 20 | | |
| | | 21 | | /// <inheritdoc /> |
| | | 22 | | public async Task<bool> GetIsAllJobsCompletedAsync(string planId, CancellationToken cancellationToken = default) |
| | | 23 | | { |
| | | 24 | | // Check if all jobs are completed. |
| | 0 | 25 | | var jobFilter = new AlterationJobFilter |
| | 0 | 26 | | { |
| | 0 | 27 | | PlanId = planId, |
| | 0 | 28 | | Statuses = [AlterationJobStatus.Pending, AlterationJobStatus.Running] |
| | 0 | 29 | | }; |
| | | 30 | | |
| | 0 | 31 | | return await jobStore.CountAsync(jobFilter, cancellationToken) == 0; |
| | 0 | 32 | | } |
| | | 33 | | |
| | | 34 | | /// <inheritdoc /> |
| | | 35 | | public async Task CompletePlanAsync(AlterationPlan plan, CancellationToken cancellationToken = default) |
| | | 36 | | { |
| | 0 | 37 | | plan.Status = AlterationPlanStatus.Completed; |
| | 0 | 38 | | plan.CompletedAt = systemClock.UtcNow; |
| | | 39 | | |
| | 0 | 40 | | await planStore.SaveAsync(plan, cancellationToken); |
| | 0 | 41 | | await notificationSender.SendAsync(new AlterationPlanCompleted(plan), cancellationToken); |
| | 0 | 42 | | } |
| | | 43 | | } |