| | | 1 | | using Elsa.Scheduling.Schedules; |
| | | 2 | | using Elsa.Scheduling.Tasks; |
| | | 3 | | |
| | | 4 | | namespace Elsa.Scheduling.Services; |
| | | 5 | | |
| | | 6 | | /// <summary> |
| | | 7 | | /// A default implementation of <see cref="IWorkflowScheduler"/> that uses the <see cref="LocalScheduler"/>. |
| | | 8 | | /// </summary> |
| | 453 | 9 | | public class DefaultWorkflowScheduler(IScheduler scheduler) : IWorkflowScheduler |
| | | 10 | | { |
| | | 11 | | /// <inheritdoc /> |
| | | 12 | | public async ValueTask ScheduleAtAsync(string taskName, ScheduleNewWorkflowInstanceRequest request, DateTimeOffset a |
| | | 13 | | { |
| | 0 | 14 | | await scheduler.ScheduleAsync(taskName, new RunWorkflowTask(request), new SpecificInstantSchedule(at), cancellat |
| | 0 | 15 | | } |
| | | 16 | | |
| | | 17 | | /// <inheritdoc /> |
| | | 18 | | public async ValueTask ScheduleAtAsync(string taskName, ScheduleExistingWorkflowInstanceRequest request, DateTimeOff |
| | | 19 | | { |
| | 17 | 20 | | var task = new ResumeWorkflowTask(request); |
| | 17 | 21 | | var schedule = new SpecificInstantSchedule(at); |
| | 17 | 22 | | await scheduler.ScheduleAsync(taskName, task, schedule, cancellationToken); |
| | 17 | 23 | | } |
| | | 24 | | |
| | | 25 | | /// <inheritdoc /> |
| | | 26 | | public async ValueTask ScheduleRecurringAsync(string taskName, ScheduleNewWorkflowInstanceRequest request, DateTimeO |
| | | 27 | | { |
| | 2 | 28 | | var task = new RunWorkflowTask(request); |
| | 2 | 29 | | var schedule = new RecurringSchedule(startAt, interval); |
| | 2 | 30 | | await scheduler.ScheduleAsync(taskName, task, schedule, cancellationToken); |
| | 2 | 31 | | } |
| | | 32 | | |
| | | 33 | | /// <inheritdoc /> |
| | | 34 | | public async ValueTask ScheduleRecurringAsync(string taskName, ScheduleExistingWorkflowInstanceRequest request, Date |
| | | 35 | | { |
| | 0 | 36 | | var task = new ResumeWorkflowTask(request); |
| | 0 | 37 | | var schedule = new RecurringSchedule(startAt, interval); |
| | 0 | 38 | | await scheduler.ScheduleAsync(taskName, task, schedule, cancellationToken); |
| | 0 | 39 | | } |
| | | 40 | | |
| | | 41 | | /// <inheritdoc /> |
| | | 42 | | public async ValueTask ScheduleCronAsync(string taskName, ScheduleNewWorkflowInstanceRequest request, string cronExp |
| | | 43 | | { |
| | 1 | 44 | | var task = new RunWorkflowTask(request); |
| | 1 | 45 | | var schedule = new CronSchedule(cronExpression); |
| | 1 | 46 | | await scheduler.ScheduleAsync(taskName, task, schedule, cancellationToken); |
| | 1 | 47 | | } |
| | | 48 | | |
| | | 49 | | /// <inheritdoc /> |
| | | 50 | | public async ValueTask ScheduleCronAsync(string taskName, ScheduleExistingWorkflowInstanceRequest request, string cr |
| | | 51 | | { |
| | 1 | 52 | | var task = new ResumeWorkflowTask(request); |
| | 1 | 53 | | var schedule = new CronSchedule(cronExpression); |
| | 1 | 54 | | await scheduler.ScheduleAsync(taskName, task, schedule, cancellationToken); |
| | 1 | 55 | | } |
| | | 56 | | |
| | | 57 | | /// <inheritdoc /> |
| | | 58 | | public async ValueTask UnscheduleAsync(string taskName, CancellationToken cancellationToken = default) |
| | | 59 | | { |
| | 33 | 60 | | await scheduler.ClearScheduleAsync(taskName, cancellationToken); |
| | 33 | 61 | | } |
| | | 62 | | } |