| | | 1 | | using CShells.Features; |
| | | 2 | | using Elsa.Common.Multitenancy; |
| | | 3 | | using Elsa.Common.ShellFeatures; |
| | | 4 | | using Elsa.Extensions; |
| | | 5 | | using Elsa.Scheduling.Bookmarks; |
| | | 6 | | using Elsa.Scheduling.Handlers; |
| | | 7 | | using Elsa.Scheduling.HostedServices; |
| | | 8 | | using Elsa.Scheduling.Services; |
| | | 9 | | using Elsa.Scheduling.TriggerPayloadValidators; |
| | | 10 | | using Elsa.Workflows.Management.Extensions; |
| | | 11 | | using JetBrains.Annotations; |
| | | 12 | | using Microsoft.Extensions.DependencyInjection; |
| | | 13 | | |
| | | 14 | | namespace Elsa.Scheduling.ShellFeatures; |
| | | 15 | | |
| | | 16 | | /// <summary> |
| | | 17 | | /// Provides scheduling features to the system. |
| | | 18 | | /// </summary> |
| | | 19 | | [ShellFeature( |
| | | 20 | | DisplayName = "Scheduling", |
| | | 21 | | Description = "Provides scheduling capabilities for workflows including cron and delay-based triggers", |
| | | 22 | | DependsOn = [typeof(SystemClockFeature)])] |
| | | 23 | | [UsedImplicitly] |
| | | 24 | | public class SchedulingFeature : IShellFeature |
| | | 25 | | { |
| | | 26 | | /// <summary> |
| | | 27 | | /// Gets or sets the trigger scheduler factory. |
| | | 28 | | /// </summary> |
| | 0 | 29 | | public Func<IServiceProvider, IWorkflowScheduler> WorkflowScheduler { get; set; } = sp => sp.GetRequiredService<Defa |
| | | 30 | | |
| | | 31 | | /// <summary> |
| | | 32 | | /// Gets or sets the CRON parser factory. |
| | | 33 | | /// </summary> |
| | 0 | 34 | | public Func<IServiceProvider, ICronParser> CronParser { get; set; } = sp => sp.GetRequiredService<CronosCronParser>( |
| | | 35 | | |
| | | 36 | | public void ConfigureServices(IServiceCollection services) |
| | | 37 | | { |
| | 0 | 38 | | services |
| | 0 | 39 | | .AddSingleton<UpdateTenantSchedules>() |
| | 0 | 40 | | .AddSingleton<ITenantActivatedEvent>(sp => sp.GetRequiredService<UpdateTenantSchedules>()) |
| | 0 | 41 | | .AddSingleton<ITenantDeletedEvent>(sp => sp.GetRequiredService<UpdateTenantSchedules>()) |
| | 0 | 42 | | .AddSingleton<IScheduler, LocalScheduler>() |
| | 0 | 43 | | .AddSingleton<CronosCronParser>() |
| | 0 | 44 | | .AddSingleton(CronParser) |
| | 0 | 45 | | .AddScoped<ITriggerScheduler, DefaultTriggerScheduler>() |
| | 0 | 46 | | .AddScoped<IBookmarkScheduler, DefaultBookmarkScheduler>() |
| | 0 | 47 | | .AddScoped<DefaultWorkflowScheduler>() |
| | 0 | 48 | | .AddScoped(WorkflowScheduler) |
| | 0 | 49 | | .AddBackgroundTask<CreateSchedulesBackgroundTask>() |
| | 0 | 50 | | .AddHandlersFrom<ScheduleWorkflows>() |
| | 0 | 51 | | .AddTriggerPayloadValidator<CronTriggerPayloadValidator, CronTriggerPayload>() |
| | 0 | 52 | | .AddActivitiesFrom<SchedulingFeature>(); |
| | 0 | 53 | | } |
| | | 54 | | } |
| | | 55 | | |