| | | 1 | | using Elsa.Mediator.Contracts; |
| | | 2 | | using Elsa.Workflows.Runtime.Notifications; |
| | | 3 | | |
| | | 4 | | namespace Elsa.Scheduling.Handlers; |
| | | 5 | | |
| | | 6 | | /// <summary> |
| | | 7 | | /// Updates scheduled jobs based on updated workflow triggers and bookmarks. |
| | | 8 | | /// </summary> |
| | | 9 | | public class ScheduleWorkflows : INotificationHandler<WorkflowTriggersIndexed>, INotificationHandler<WorkflowBookmarksIn |
| | | 10 | | { |
| | | 11 | | private readonly ITriggerScheduler _triggerScheduler; |
| | | 12 | | private readonly IBookmarkScheduler _bookmarkScheduler; |
| | | 13 | | |
| | | 14 | | /// <summary> |
| | | 15 | | /// Initializes a new instance of the <see cref="ScheduleWorkflows"/> class. |
| | | 16 | | /// </summary> |
| | 453 | 17 | | public ScheduleWorkflows(ITriggerScheduler triggerScheduler, IBookmarkScheduler bookmarkScheduler) |
| | | 18 | | { |
| | 453 | 19 | | _triggerScheduler = triggerScheduler; |
| | 453 | 20 | | _bookmarkScheduler = bookmarkScheduler; |
| | 453 | 21 | | } |
| | | 22 | | |
| | | 23 | | /// <summary> |
| | | 24 | | /// Updates scheduled jobs based on updated triggers. |
| | | 25 | | /// </summary> |
| | | 26 | | public async Task HandleAsync(WorkflowTriggersIndexed notification, CancellationToken cancellationToken) |
| | | 27 | | { |
| | 633 | 28 | | await _triggerScheduler.UnscheduleAsync(notification.IndexedWorkflowTriggers.RemovedTriggers, cancellationToken) |
| | 633 | 29 | | await _triggerScheduler.ScheduleAsync(notification.IndexedWorkflowTriggers.AddedTriggers, cancellationToken); |
| | 633 | 30 | | } |
| | | 31 | | |
| | | 32 | | /// <summary> |
| | | 33 | | /// Updates scheduled jobs based on updated bookmarks. |
| | | 34 | | /// </summary> |
| | | 35 | | public async Task HandleAsync(WorkflowBookmarksIndexed notification, CancellationToken cancellationToken) |
| | | 36 | | { |
| | 457 | 37 | | var workflowInstanceId = notification.IndexedWorkflowBookmarks.WorkflowExecutionContext.Id; |
| | 457 | 38 | | await _bookmarkScheduler.UnscheduleAsync(notification.IndexedWorkflowBookmarks.RemovedBookmarks, cancellationTok |
| | 457 | 39 | | await _bookmarkScheduler.ScheduleAsync(workflowInstanceId, notification.IndexedWorkflowBookmarks.AddedBookmarks, |
| | 457 | 40 | | } |
| | | 41 | | } |