-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Expand file tree
/
Copy pathSchedulingFeature.cs
More file actions
68 lines (63 loc) · 2.67 KB
/
Copy pathSchedulingFeature.cs
File metadata and controls
68 lines (63 loc) · 2.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
using CShells.Features;
using Elsa.Common.Multitenancy;
using Elsa.Common.ShellFeatures;
using Elsa.Extensions;
using Elsa.Workflows.Options;
using Elsa.Scheduling.Bookmarks;
using Elsa.Scheduling.Handlers;
using Elsa.Scheduling.Options;
using Elsa.Scheduling.Services;
using Elsa.Scheduling.StartupTasks;
using Elsa.Scheduling.TriggerPayloadValidators;
using Elsa.Workflows.Management.Extensions;
using JetBrains.Annotations;
using Microsoft.Extensions.DependencyInjection;
using Elsa.Common.Serialization;
namespace Elsa.Scheduling.ShellFeatures;
/// <summary>
/// Provides scheduling features to the system.
/// </summary>
[ShellFeature(
DisplayName = "Scheduling",
Description = "Provides scheduling capabilities for workflows including cron and delay-based triggers",
DependsOn = [typeof(SystemClockFeature)])]
[UsedImplicitly]
public class SchedulingFeature : IShellFeature
{
/// <summary>
/// Gets or sets the trigger scheduler factory.
/// </summary>
public Func<IServiceProvider, IWorkflowScheduler> WorkflowScheduler { get; set; } = sp => sp.GetRequiredService<DefaultWorkflowScheduler>();
/// <summary>
/// Gets or sets the CRON parser factory.
/// </summary>
public Func<IServiceProvider, ICronParser> CronParser { get; set; } = sp => sp.GetRequiredService<CronosCronParser>();
public void ConfigureServices(IServiceCollection services)
{
services
.AddSingleton<UpdateTenantSchedules>()
.AddSingleton<ITenantDeletedEvent>(sp => sp.GetRequiredService<UpdateTenantSchedules>())
.AddSingleton<IScheduler, LocalScheduler>()
.AddSingleton<PastDueScheduleStaggerer>()
.AddSingleton<CronosCronParser>()
.AddSingleton(CronParser)
.AddScoped<ITriggerScheduler, DefaultTriggerScheduler>()
.AddScoped<IBookmarkScheduler, DefaultBookmarkScheduler>()
.AddScoped<DefaultWorkflowScheduler>()
.AddScoped(WorkflowScheduler)
.AddStartupTask<CreateSchedulesStartupTask>()
.AddHandlersFrom<ScheduleWorkflows>()
.AddTriggerPayloadValidator<CronTriggerPayloadValidator, CronTriggerPayload>()
.AddActivitiesFrom<SchedulingFeature>();
services.Configure<SchedulingOptions>(_ => { });
services.Configure<SerializationTypeOptions>(options =>
{
options.AddTypeAlias<CronBookmarkPayload>();
options.AddTypeAlias<CronTriggerPayload>();
options.AddTypeAlias<DelayPayload>();
options.AddTypeAlias<StartAtPayload>();
options.AddTypeAlias<TimerBookmarkPayload>();
options.AddTypeAlias<TimerTriggerPayload>();
});
}
}