| | | 1 | | using Elsa.Common.Features; |
| | | 2 | | using Elsa.Common.Multitenancy; |
| | | 3 | | using Elsa.Expressions.Options; |
| | | 4 | | using Elsa.Extensions; |
| | | 5 | | using Elsa.Features.Abstractions; |
| | | 6 | | using Elsa.Features.Attributes; |
| | | 7 | | using Elsa.Features.Services; |
| | | 8 | | using Elsa.Scheduling.Bookmarks; |
| | | 9 | | using Elsa.Scheduling.Handlers; |
| | | 10 | | using Elsa.Scheduling.Services; |
| | | 11 | | using Elsa.Scheduling.StartupTasks; |
| | | 12 | | using Elsa.Scheduling.TriggerPayloadValidators; |
| | | 13 | | using Elsa.Workflows.Management.Features; |
| | | 14 | | using Microsoft.Extensions.DependencyInjection; |
| | | 15 | | |
| | | 16 | | namespace Elsa.Scheduling.Features; |
| | | 17 | | |
| | | 18 | | /// <summary> |
| | | 19 | | /// Provides scheduling features to the system. |
| | | 20 | | /// </summary> |
| | | 21 | | [DependsOn(typeof(SystemClockFeature))] |
| | | 22 | | public class SchedulingFeature : FeatureBase |
| | | 23 | | { |
| | | 24 | | /// <inheritdoc /> |
| | 213 | 25 | | public SchedulingFeature(IModule module) : base(module) |
| | | 26 | | { |
| | 213 | 27 | | } |
| | | 28 | | |
| | | 29 | | /// <summary> |
| | | 30 | | /// Gets or sets the trigger scheduler. |
| | | 31 | | /// </summary> |
| | 1050 | 32 | | public Func<IServiceProvider, IWorkflowScheduler> WorkflowScheduler { get; set; } = sp => sp.GetRequiredService<Defa |
| | | 33 | | |
| | | 34 | | /// <summary> |
| | | 35 | | /// Gets or sets the CRON parser. |
| | | 36 | | /// </summary> |
| | 429 | 37 | | public Func<IServiceProvider, ICronParser> CronParser { get; set; } = sp => sp.GetRequiredService<CronosCronParser>( |
| | | 38 | | |
| | | 39 | | /// <inheritdoc /> |
| | | 40 | | public override void Apply() |
| | | 41 | | { |
| | 213 | 42 | | Services |
| | 213 | 43 | | .AddSingleton<UpdateTenantSchedules>() |
| | 72 | 44 | | .AddSingleton<ITenantDeletedEvent>(sp => sp.GetRequiredService<UpdateTenantSchedules>()) |
| | 213 | 45 | | .AddSingleton<IScheduler, LocalScheduler>() |
| | 213 | 46 | | .AddSingleton<CronosCronParser>() |
| | 213 | 47 | | .AddSingleton(CronParser) |
| | 213 | 48 | | .AddScoped<ITriggerScheduler, DefaultTriggerScheduler>() |
| | 213 | 49 | | .AddScoped<IBookmarkScheduler, DefaultBookmarkScheduler>() |
| | 213 | 50 | | .AddScoped<DefaultWorkflowScheduler>() |
| | 213 | 51 | | .AddScoped(WorkflowScheduler) |
| | 213 | 52 | | .AddStartupTask<CreateSchedulesStartupTask>() |
| | 213 | 53 | | .AddHandlersFrom<ScheduleWorkflows>() |
| | 213 | 54 | | |
| | 213 | 55 | | //Trigger payload validators. |
| | 213 | 56 | | .AddTriggerPayloadValidator<CronTriggerPayloadValidator, CronTriggerPayload>() |
| | 213 | 57 | | |
| | 213 | 58 | | // Graceful shutdown: register scheduled-trigger ingress for diagnostic visibility (FR-006). |
| | 213 | 59 | | .AddSingleton<Elsa.Workflows.Runtime.IIngressSource, Elsa.Scheduling.IngressSources.ScheduledTriggerIngressS |
| | | 60 | | |
| | 213 | 61 | | Services.Configure<ExpressionOptions>(options => |
| | 213 | 62 | | { |
| | 193 | 63 | | options.AddTypeAlias<CronBookmarkPayload>(); |
| | 193 | 64 | | options.AddTypeAlias<CronTriggerPayload>(); |
| | 193 | 65 | | options.AddTypeAlias<DelayPayload>(); |
| | 193 | 66 | | options.AddTypeAlias<StartAtPayload>(); |
| | 193 | 67 | | options.AddTypeAlias<TimerBookmarkPayload>(); |
| | 193 | 68 | | options.AddTypeAlias<TimerTriggerPayload>(); |
| | 406 | 69 | | }); |
| | | 70 | | |
| | 426 | 71 | | Module.Configure<WorkflowManagementFeature>(management => management.AddActivitiesFrom<SchedulingFeature>()); |
| | 213 | 72 | | } |
| | | 73 | | } |