| | | 1 | | using System.Diagnostics.CodeAnalysis; |
| | | 2 | | using System.Reflection; |
| | | 3 | | using CShells.Features; |
| | | 4 | | using Elsa.Common; |
| | | 5 | | using Elsa.Common.RecurringTasks; |
| | | 6 | | using Elsa.Extensions; |
| | | 7 | | using Elsa.Mediator.Contracts; |
| | | 8 | | using Elsa.Workflows.CommitStates; |
| | | 9 | | using Elsa.Workflows.Management; |
| | | 10 | | using Elsa.Workflows.Management.Contracts; |
| | | 11 | | using Elsa.Workflows.Management.Services; |
| | | 12 | | using Elsa.Workflows.Options; |
| | | 13 | | using Elsa.Workflows.Runtime.ActivationValidators; |
| | | 14 | | using Elsa.Workflows.Runtime.Discovery; |
| | | 15 | | using Elsa.Workflows.Runtime.Entities; |
| | | 16 | | using Elsa.Workflows.Runtime.Handlers; |
| | | 17 | | using Elsa.Workflows.Runtime.Options; |
| | | 18 | | using Elsa.Workflows.Runtime.Providers; |
| | | 19 | | using Elsa.Workflows.Runtime.Services; |
| | | 20 | | using Elsa.Workflows.Runtime.Stores; |
| | | 21 | | using Elsa.Workflows.Runtime.Tasks; |
| | | 22 | | using Elsa.Workflows.Runtime.UIHints; |
| | | 23 | | using Medallion.Threading; |
| | | 24 | | using Medallion.Threading.FileSystem; |
| | | 25 | | using Microsoft.Extensions.DependencyInjection; |
| | | 26 | | using Microsoft.Extensions.DependencyInjection.Extensions; |
| | | 27 | | using Microsoft.Extensions.Options; |
| | | 28 | | using Elsa.Common.Serialization; |
| | | 29 | | |
| | | 30 | | namespace Elsa.Workflows.Runtime.ShellFeatures; |
| | | 31 | | |
| | | 32 | | /// <summary> |
| | | 33 | | /// Installs and configures workflow runtime features. |
| | | 34 | | /// </summary> |
| | | 35 | | [ShellFeature( |
| | | 36 | | DisplayName = "Workflow Runtime", |
| | | 37 | | Description = "Provides workflow execution runtime and scheduling capabilities", |
| | | 38 | | DependsOn = ["Workflows"])] |
| | | 39 | | public class WorkflowRuntimeFeature : IShellFeature |
| | | 40 | | { |
| | 18 | 41 | | private IDictionary<string, DispatcherChannel> WorkflowDispatcherChannels { get; set; } = new Dictionary<string, Dis |
| | | 42 | | |
| | | 43 | | /// <summary> |
| | | 44 | | /// A list of workflow builders configured during application startup. |
| | | 45 | | /// </summary> |
| | 30 | 46 | | public IDictionary<string, Func<IServiceProvider, ValueTask<IWorkflow>>> Workflows { get; set; } = new Dictionary<st |
| | 22 | 47 | | private ISet<Type> WorkflowTypes { get; } = new HashSet<Type>(); |
| | | 48 | | |
| | | 49 | | /// <summary> |
| | | 50 | | /// A factory that instantiates a concrete <see cref="IWorkflowRuntime"/>. |
| | | 51 | | /// </summary> |
| | 18 | 52 | | public Func<IServiceProvider, IWorkflowRuntime> WorkflowRuntime { get; set; } = sp => ActivatorUtilities.CreateInsta |
| | | 53 | | |
| | | 54 | | /// <summary> |
| | | 55 | | /// A factory that instantiates an <see cref="IWorkflowDispatcher"/>. |
| | | 56 | | /// </summary> |
| | 18 | 57 | | public Func<IServiceProvider, IWorkflowDispatcher> WorkflowDispatcher { get; set; } = sp => |
| | 18 | 58 | | { |
| | 0 | 59 | | var decoratedService = ActivatorUtilities.CreateInstance<BackgroundWorkflowDispatcher>(sp); |
| | 0 | 60 | | var transactionalService = ActivatorUtilities.CreateInstance<TransactionalWorkflowDispatcher>(sp, decoratedServi |
| | 0 | 61 | | return ActivatorUtilities.CreateInstance<ValidatingWorkflowDispatcher>(sp, transactionalService); |
| | 18 | 62 | | }; |
| | | 63 | | |
| | | 64 | | /// <summary> |
| | | 65 | | /// A factory that instantiates an <see cref="IStimulusDispatcher"/>. |
| | | 66 | | /// </summary> |
| | 18 | 67 | | public Func<IServiceProvider, IStimulusDispatcher> StimulusDispatcher { get; set; } = sp => ActivatorUtilities.Creat |
| | | 68 | | |
| | | 69 | | /// <summary> |
| | | 70 | | /// A factory that instantiates an <see cref="IWorkflowCancellationDispatcher"/>. |
| | | 71 | | /// </summary> |
| | 18 | 72 | | public Func<IServiceProvider, IWorkflowCancellationDispatcher> WorkflowCancellationDispatcher { get; set; } = sp => |
| | | 73 | | |
| | | 74 | | /// <summary> |
| | | 75 | | /// A factory that instantiates an <see cref="IWorkflowDispatchOutboxStore"/>. |
| | | 76 | | /// </summary> |
| | 18 | 77 | | public Func<IServiceProvider, IWorkflowDispatchOutboxStore> WorkflowDispatchOutboxStore { get; set; } = sp => Activa |
| | | 78 | | |
| | | 79 | | /// <summary> |
| | | 80 | | /// A factory that instantiates an <see cref="IBookmarkStore"/>. |
| | | 81 | | /// </summary> |
| | 18 | 82 | | public Func<IServiceProvider, IBookmarkStore> BookmarkStore { get; set; } = sp => sp.GetRequiredService<MemoryBookma |
| | | 83 | | |
| | | 84 | | /// <summary> |
| | | 85 | | /// A factory that instantiates an <see cref="IBookmarkQueueStore"/>. |
| | | 86 | | /// </summary> |
| | 18 | 87 | | public Func<IServiceProvider, IBookmarkQueueStore> BookmarkQueueStore { get; set; } = sp => sp.GetRequiredService<Me |
| | | 88 | | |
| | | 89 | | /// <summary> |
| | | 90 | | /// A factory that instantiates an <see cref="IBookmarkQueueDeadLetterStore"/>. |
| | | 91 | | /// </summary> |
| | 18 | 92 | | public Func<IServiceProvider, IBookmarkQueueDeadLetterStore> BookmarkQueueDeadLetterStore { get; set; } = sp => sp.G |
| | | 93 | | |
| | | 94 | | /// <summary> |
| | | 95 | | /// A factory that instantiates an <see cref="ITriggerStore"/>. |
| | | 96 | | /// </summary> |
| | 18 | 97 | | public Func<IServiceProvider, ITriggerStore> TriggerStore { get; set; } = sp => sp.GetRequiredService<MemoryTriggerS |
| | | 98 | | |
| | | 99 | | /// <summary> |
| | | 100 | | /// A factory that instantiates an <see cref="IWorkflowExecutionLogStore"/>. |
| | | 101 | | /// </summary> |
| | 18 | 102 | | public Func<IServiceProvider, IWorkflowExecutionLogStore> WorkflowExecutionLogStore { get; set; } = sp => sp.GetRequ |
| | | 103 | | |
| | | 104 | | /// <summary> |
| | | 105 | | /// A factory that instantiates an <see cref="IActivityExecutionStore"/>. |
| | | 106 | | /// </summary> |
| | 18 | 107 | | public Func<IServiceProvider, IActivityExecutionStore> ActivityExecutionLogStore { get; set; } = sp => sp.GetRequire |
| | | 108 | | |
| | | 109 | | /// <summary> |
| | | 110 | | /// A factory that instantiates an <see cref="IDistributedLockProvider"/>. |
| | | 111 | | /// </summary> |
| | 18 | 112 | | public Func<IServiceProvider, IDistributedLockProvider> DistributedLockProvider { get; set; } = _ => new FileDistrib |
| | | 113 | | |
| | | 114 | | /// <summary> |
| | | 115 | | /// A factory that instantiates an <see cref="ITaskDispatcher"/>. |
| | | 116 | | /// </summary> |
| | 18 | 117 | | public Func<IServiceProvider, ITaskDispatcher> RunTaskDispatcher { get; set; } = sp => sp.GetRequiredService<Backgro |
| | | 118 | | |
| | | 119 | | /// <summary> |
| | | 120 | | /// A factory that instantiates an <see cref="IBackgroundActivityScheduler"/>. |
| | | 121 | | /// </summary> |
| | 18 | 122 | | public Func<IServiceProvider, IBackgroundActivityScheduler> BackgroundActivityScheduler { get; set; } = sp => Activa |
| | | 123 | | |
| | | 124 | | /// <summary> |
| | | 125 | | /// A factory that instantiates a log record sink for an <see cref="ActivityExecutionRecord"/>. |
| | | 126 | | /// </summary> |
| | 18 | 127 | | public Func<IServiceProvider, ILogRecordSink<ActivityExecutionRecord>> ActivityExecutionLogSink { get; set; } = sp = |
| | | 128 | | |
| | | 129 | | /// <summary> |
| | | 130 | | /// A factory that instantiates a log record sink for an <see cref="WorkflowExecutionLogRecord"/>. |
| | | 131 | | /// </summary> |
| | 18 | 132 | | public Func<IServiceProvider, ILogRecordSink<WorkflowExecutionLogRecord>> WorkflowExecutionLogSink { get; set; } = s |
| | | 133 | | |
| | | 134 | | /// <summary> |
| | | 135 | | /// A factory that instantiates an <see cref="ICommandHandler"/>. |
| | | 136 | | /// </summary> |
| | 18 | 137 | | public Func<IServiceProvider, ICommandHandler> DispatchWorkflowCommandHandler { get; set; } = sp => sp.GetRequiredSe |
| | | 138 | | |
| | | 139 | | /// <summary> |
| | | 140 | | /// A factory that instantiates an <see cref="IWorkflowResumer"/>. |
| | | 141 | | /// </summary> |
| | 18 | 142 | | public Func<IServiceProvider, IWorkflowResumer> WorkflowResumer { get; set; } = sp => sp.GetRequiredService<Workflow |
| | | 143 | | |
| | | 144 | | /// <summary> |
| | | 145 | | /// A factory that instantiates an <see cref="IBookmarkQueueWorker"/>. |
| | | 146 | | /// </summary> |
| | 18 | 147 | | public Func<IServiceProvider, IBookmarkQueueWorker> BookmarkQueueWorker { get; set; } = sp => sp.GetRequiredService< |
| | | 148 | | |
| | | 149 | | /// <summary> |
| | | 150 | | /// Callback that tunes the graceful-shutdown machinery (drain deadline, per-source pause timeout, stimulus-queue ba |
| | | 151 | | /// pause-persistence policy). Applied when <see cref="ConfigureServices"/> binds <see cref="GracefulShutdownOptions |
| | | 152 | | /// </summary> |
| | 0 | 153 | | public GracefulShutdownOptions? GracefulShutdown { get; set; } |
| | | 154 | | |
| | | 155 | | /// <summary> |
| | | 156 | | /// Register the specified workflow type. |
| | | 157 | | /// </summary> |
| | | 158 | | public WorkflowRuntimeFeature AddWorkflow<T>() where T : IWorkflow |
| | | 159 | | { |
| | 0 | 160 | | return AddWorkflow(typeof(T)); |
| | | 161 | | } |
| | | 162 | | |
| | | 163 | | /// <summary> |
| | | 164 | | /// Register the specified workflow type. |
| | | 165 | | /// </summary> |
| | | 166 | | public WorkflowRuntimeFeature AddWorkflow(Type workflowType) |
| | | 167 | | { |
| | 6 | 168 | | Workflows.Add(workflowType); |
| | 2 | 169 | | WorkflowTypes.Add(workflowType); |
| | 2 | 170 | | return this; |
| | | 171 | | } |
| | | 172 | | |
| | | 173 | | /// <summary> |
| | | 174 | | /// Register all workflows in the specified assembly. |
| | | 175 | | /// </summary> |
| | | 176 | | [RequiresUnreferencedCode("The assembly is required to be referenced.")] |
| | | 177 | | public WorkflowRuntimeFeature AddWorkflowsFrom(Assembly assembly) |
| | | 178 | | { |
| | 0 | 179 | | foreach (var workflowType in WorkflowTypeScanner.GetWorkflowTypes(assembly)) |
| | 0 | 180 | | AddWorkflow(workflowType); |
| | | 181 | | |
| | 0 | 182 | | return this; |
| | | 183 | | } |
| | | 184 | | |
| | | 185 | | public void ConfigureServices(IServiceCollection services) |
| | | 186 | | { |
| | | 187 | | // Options. |
| | 0 | 188 | | services.Configure<SerializationTypeOptions>(RegisterWorkflowTypeAliases); |
| | 0 | 189 | | services.Configure<RuntimeOptions>(options => { options.Workflows = Workflows; }); |
| | 0 | 190 | | services.Configure<WorkflowDispatcherOptions>(options => |
| | 0 | 191 | | { |
| | 0 | 192 | | options.Channels.AddRange(WorkflowDispatcherChannels.Values); |
| | 0 | 193 | | }); |
| | 0 | 194 | | services.AddGracefulShutdownOptions(options => |
| | 0 | 195 | | { |
| | 0 | 196 | | if (GracefulShutdown == null) |
| | 0 | 197 | | return; |
| | 0 | 198 | | |
| | 0 | 199 | | options.DrainDeadline = GracefulShutdown.DrainDeadline; |
| | 0 | 200 | | options.IngressPauseTimeout = GracefulShutdown.IngressPauseTimeout; |
| | 0 | 201 | | options.StimulusQueueMaxDepthWhilePaused = GracefulShutdown.StimulusQueueMaxDepthWhilePaused; |
| | 0 | 202 | | options.OverflowPolicy = GracefulShutdown.OverflowPolicy; |
| | 0 | 203 | | options.PausePersistence = GracefulShutdown.PausePersistence; |
| | 0 | 204 | | options.MaxForceCancelledInstanceIdsReported = GracefulShutdown.MaxForceCancelledInstanceIdsReported; |
| | 0 | 205 | | }); |
| | | 206 | | |
| | 0 | 207 | | services |
| | 0 | 208 | | // Graceful-shutdown core (US1 — quiescence machinery). |
| | 0 | 209 | | // Per-shell QuiescenceSignal: the persistence key includes the shell id so multi-shell deployments under |
| | 0 | 210 | | // PausePersistencePolicy.AcrossReactivations don't collide on a single key. Falls back to "default" only |
| | 0 | 211 | | // when ShellSettings isn't in the DI graph (degenerate single-shell or non-CShells host). |
| | 0 | 212 | | .AddSingleton<IQuiescenceSignal>(sp => new QuiescenceSignal( |
| | 0 | 213 | | sp.GetRequiredService<IOptions<GracefulShutdownOptions>>(), |
| | 0 | 214 | | sp.GetRequiredService<ISystemClock>(), |
| | 0 | 215 | | sp.GetRequiredService<IExecutionCycleRegistry>(), |
| | 0 | 216 | | sp.GetRequiredService<IServiceScopeFactory>(), |
| | 0 | 217 | | shellName: sp.GetService<CShells.ShellSettings>()?.Id)) |
| | 0 | 218 | | .AddSingleton<IIngressSourceRegistry, IngressSourceRegistry>() |
| | 0 | 219 | | .AddSingleton<IExecutionCycleRegistry, ExecutionCycleRegistry>() |
| | 0 | 220 | | .AddSingleton(sp => new Lazy<IEnumerable<IIngressSource>>(sp.GetServices<IIngressSource>)) |
| | 0 | 221 | | .AddSingleton<IDrainOrchestrator, DrainOrchestrator>() |
| | 0 | 222 | | .AddScoped<IWorkflowRuntimeAdminService, WorkflowRuntimeAdminService>() |
| | 0 | 223 | | .AddTransient<CShells.Lifecycle.IDrainHandler, Lifecycle.ElsaShellDrainHandler>() |
| | 0 | 224 | | .AddScoped<IInterruptedRecoveryScanner, InterruptedRecoveryScanner>() |
| | 0 | 225 | | .AddStartupTask<StartupTasks.RecoverInterruptedWorkflowsStartupTask>() |
| | 0 | 226 | | .AddSingleton<IIngressSource, IngressSources.InternalBookmarkQueueIngressSource>() |
| | 0 | 227 | | .AddTransient<CShells.Lifecycle.IShellInitializer, Lifecycle.InitializePauseStateShellInitializer>() |
| | 0 | 228 | | |
| | 0 | 229 | | // Core. |
| | 0 | 230 | | .AddScoped<ITriggerIndexer, TriggerIndexer>() |
| | 0 | 231 | | .AddScoped<IWorkflowInstanceFactory, WorkflowInstanceFactory>() |
| | 0 | 232 | | .AddScoped<IWorkflowHostFactory, WorkflowHostFactory>() |
| | 0 | 233 | | .AddScoped<IBackgroundActivityInvoker, BackgroundActivityInvoker>() |
| | 0 | 234 | | .AddScoped(WorkflowRuntime) |
| | 0 | 235 | | .AddScoped(WorkflowDispatcher) |
| | 0 | 236 | | .AddScoped(StimulusDispatcher) |
| | 0 | 237 | | .AddScoped(WorkflowCancellationDispatcher) |
| | 0 | 238 | | .AddScoped(RunTaskDispatcher) |
| | 0 | 239 | | .AddScoped(ActivityExecutionLogSink) |
| | 0 | 240 | | .AddScoped(WorkflowExecutionLogSink) |
| | 0 | 241 | | .AddSingleton(BackgroundActivityScheduler) |
| | 0 | 242 | | .AddSingleton<RandomLongIdentityGenerator>() |
| | 0 | 243 | | .AddSingleton<IBookmarkQueueSignaler, BookmarkQueueSignaler>() |
| | 0 | 244 | | .AddScoped(BookmarkQueueWorker) |
| | 0 | 245 | | .AddScoped<IBookmarkManager, DefaultBookmarkManager>() |
| | 0 | 246 | | .AddScoped<IActivityExecutionManager, DefaultActivityExecutionManager>() |
| | 0 | 247 | | .AddScoped<IActivityExecutionStatsService, ActivityExecutionStatsService>() |
| | 0 | 248 | | .AddScoped<IActivityExecutionMapper, DefaultActivityExecutionMapper>() |
| | 0 | 249 | | .AddScoped<IWorkflowDefinitionStorePopulator, DefaultWorkflowDefinitionStorePopulator>() |
| | 0 | 250 | | .AddScoped<IRegistriesPopulator, DefaultRegistriesPopulator>() |
| | 0 | 251 | | .AddScoped<IWorkflowDefinitionsRefresher, WorkflowDefinitionsRefresher>() |
| | 0 | 252 | | .AddScoped<IWorkflowDefinitionsReloader, WorkflowDefinitionsReloader>() |
| | 0 | 253 | | .AddScoped<IWorkflowRegistry, DefaultWorkflowRegistry>() |
| | 0 | 254 | | .AddScoped<IWorkflowMatcher, WorkflowMatcher>() |
| | 0 | 255 | | .AddScoped<IWorkflowInvoker, WorkflowInvoker>() |
| | 0 | 256 | | .AddScoped<IStimulusSender, StimulusSender>() |
| | 0 | 257 | | .AddScoped<ITriggerBoundWorkflowService, TriggerBoundWorkflowService>() |
| | 0 | 258 | | .AddScoped<IBookmarkBoundWorkflowService, BookmarkBoundWorkflowService>() |
| | 0 | 259 | | .AddScoped<ITaskReporter, TaskReporter>() |
| | 0 | 260 | | .AddScoped<SynchronousTaskDispatcher>() |
| | 0 | 261 | | .AddScoped<BackgroundTaskDispatcher>() |
| | 0 | 262 | | .AddScoped<StoreActivityExecutionLogSink>() |
| | 0 | 263 | | .AddScoped<StoreWorkflowExecutionLogSink>() |
| | 0 | 264 | | .AddScoped<DispatchWorkflowCommandHandler>() |
| | 0 | 265 | | .AddScoped<IEventPublisher, EventPublisher>() |
| | 0 | 266 | | .AddScoped<IBookmarkUpdater, BookmarkUpdater>() |
| | 0 | 267 | | .AddScoped<IBookmarksPersister, BookmarksPersister>() |
| | 0 | 268 | | .AddScoped<IBookmarkResumer, BookmarkResumer>() |
| | 0 | 269 | | .AddScoped<IBookmarkQueue, StoreBookmarkQueue>() |
| | 0 | 270 | | .AddScoped<IBookmarkQueueDeadLetterManager, BookmarkQueueDeadLetterManager>() |
| | 0 | 271 | | .AddScoped<WorkflowResumer>() |
| | 0 | 272 | | .AddScoped<BookmarkQueueWorker>() |
| | 0 | 273 | | .AddScoped(WorkflowResumer) |
| | 0 | 274 | | .AddScoped<ITriggerInvoker, TriggerInvoker>() |
| | 0 | 275 | | .AddScoped<IWorkflowCanceler, WorkflowCanceler>() |
| | 0 | 276 | | .AddScoped<IWorkflowCancellationService, WorkflowCancellationService>() |
| | 0 | 277 | | .AddScoped<IWorkflowActivationStrategyEvaluator, DefaultWorkflowActivationStrategyEvaluator>() |
| | 0 | 278 | | .AddScoped<IWorkflowStarter, DefaultWorkflowStarter>() |
| | 0 | 279 | | .AddScoped<IWorkflowRestarter, DefaultWorkflowRestarter>() |
| | 0 | 280 | | .AddScoped<IBookmarkQueuePurger, DefaultBookmarkQueuePurger>() |
| | 0 | 281 | | .AddSingleton<IWorkflowDispatchOutboxAccessor, WorkflowDispatchOutboxAccessor>() |
| | 0 | 282 | | .AddScoped<ILogRecordExtractor<WorkflowExecutionLogRecord>, WorkflowExecutionLogRecordExtractor>() |
| | 0 | 283 | | .AddScoped<IActivityPropertyLogPersistenceEvaluator, ActivityPropertyLogPersistenceEvaluator>() |
| | 0 | 284 | | .AddScoped<IBookmarkQueueProcessor, BookmarkQueueProcessor>() |
| | 0 | 285 | | .AddScoped<DefaultCommitStateHandler>() |
| | 0 | 286 | | // Decorator: disposes the execution cycle handle AFTER the workflow runner's terminal commit has persisted |
| | 0 | 287 | | // so the drain orchestrator's force-cancel path can sequence its Interrupted write to land last. |
| | 0 | 288 | | .AddScoped<ICommitStateHandler, ExecutionCycleAwareCommitStateHandler>() |
| | 0 | 289 | | .AddScoped<WorkflowHeartbeatGeneratorFactory>() |
| | 0 | 290 | | |
| | 0 | 291 | | // Deprecated services. |
| | 0 | 292 | | .AddScoped<IWorkflowInbox, StimulusProxyWorkflowInbox>() |
| | 0 | 293 | | |
| | 0 | 294 | | // Stores. |
| | 0 | 295 | | .AddScoped(BookmarkStore) |
| | 0 | 296 | | .AddScoped(BookmarkQueueStore) |
| | 0 | 297 | | .AddScoped(BookmarkQueueDeadLetterStore) |
| | 0 | 298 | | .AddScoped(TriggerStore) |
| | 0 | 299 | | .AddScoped(WorkflowExecutionLogStore) |
| | 0 | 300 | | .AddScoped(ActivityExecutionLogStore) |
| | 0 | 301 | | |
| | 0 | 302 | | // Lazy services. |
| | 0 | 303 | | .AddScoped<Func<IEnumerable<IWorkflowsProvider>>>(sp => sp.GetServices<IWorkflowsProvider>) |
| | 0 | 304 | | .AddScoped<Func<IEnumerable<IWorkflowMaterializer>>>(sp => sp.GetServices<IWorkflowMaterializer>) |
| | 0 | 305 | | |
| | 0 | 306 | | // Noop stores. |
| | 0 | 307 | | .AddScoped<MemoryWorkflowExecutionLogStore>() |
| | 0 | 308 | | .AddScoped<MemoryActivityExecutionStore>() |
| | 0 | 309 | | |
| | 0 | 310 | | // Memory stores. |
| | 0 | 311 | | .AddMemoryStore<StoredBookmark, MemoryBookmarkStore>() |
| | 0 | 312 | | .AddMemoryStore<StoredTrigger, MemoryTriggerStore>() |
| | 0 | 313 | | .AddMemoryStore<BookmarkQueueItem, MemoryBookmarkQueueStore>() |
| | 0 | 314 | | .AddMemoryStore<BookmarkQueueDeadLetterItem, MemoryBookmarkQueueDeadLetterStore>() |
| | 0 | 315 | | .AddMemoryStore<WorkflowExecutionLogRecord, MemoryWorkflowExecutionLogStore>() |
| | 0 | 316 | | .AddMemoryStore<ActivityExecutionRecord, MemoryActivityExecutionStore>() |
| | 0 | 317 | | |
| | 0 | 318 | | // Startup tasks, background tasks, and recurring tasks. |
| | 0 | 319 | | .AddStartupTask<PopulateRegistriesStartupTask>() |
| | 0 | 320 | | .AddRecurringTask<TriggerBookmarkQueueRecurringTask>(TimeSpan.FromMinutes(1)) |
| | 0 | 321 | | .AddRecurringTask<PurgeBookmarkQueueRecurringTask>(TimeSpan.FromSeconds(10)) |
| | 0 | 322 | | .AddRecurringTask<RestartInterruptedWorkflowsTask>(TimeSpan.FromMinutes(5)) // Same default as the workflow |
| | 0 | 323 | | .AddRecurringTask<ProcessWorkflowDispatchOutboxRecurringTask>(TimeSpan.FromSeconds(10)) |
| | 0 | 324 | | |
| | 0 | 325 | | // Distributed locking. |
| | 0 | 326 | | .AddSingleton(DistributedLockProvider) |
| | 0 | 327 | | |
| | 0 | 328 | | // Workflow providers. |
| | 0 | 329 | | .AddWorkflowsProvider<ClrWorkflowsProvider>() |
| | 0 | 330 | | |
| | 0 | 331 | | // UI property handlers. |
| | 0 | 332 | | .AddScoped<IPropertyUIHandler, DispatcherChannelOptionsProvider>() |
| | 0 | 333 | | |
| | 0 | 334 | | // Domain handlers. |
| | 0 | 335 | | .AddCommandHandler<DispatchWorkflowCommandHandler>() |
| | 0 | 336 | | .AddCommandHandler<DispatchStimulusCommandHandler>() |
| | 0 | 337 | | .AddCommandHandler<CancelWorkflowsCommandHandler>() |
| | 0 | 338 | | .AddNotificationHandler<ResumeDispatchWorkflowActivity>() |
| | 0 | 339 | | .AddNotificationHandler<ResumeBulkDispatchWorkflowActivity>() |
| | 0 | 340 | | .AddNotificationHandler<ProcessWorkflowDispatchOutbox>() |
| | 0 | 341 | | .AddNotificationHandler<ResumeExecuteWorkflowActivity>() |
| | 0 | 342 | | .AddNotificationHandler<IndexTriggers>() |
| | 0 | 343 | | .AddNotificationHandler<CancelBackgroundActivities>() |
| | 0 | 344 | | .AddNotificationHandler<DeleteBookmarks>() |
| | 0 | 345 | | .AddNotificationHandler<DeleteTriggers>() |
| | 0 | 346 | | .AddNotificationHandler<DeleteActivityExecutionLogRecords>() |
| | 0 | 347 | | .AddNotificationHandler<DeleteWorkflowExecutionLogRecords>() |
| | 0 | 348 | | .AddNotificationHandler<RefreshActivityRegistry>() |
| | 0 | 349 | | .AddNotificationHandler<SignalBookmarkQueueWorker>() |
| | 0 | 350 | | .AddNotificationHandler<EvaluateParentLogPersistenceModes>() |
| | 0 | 351 | | .AddNotificationHandler<CaptureActivityExecutionState>() |
| | 0 | 352 | | .AddNotificationHandler<ValidateWorkflowRequestHandler>() |
| | 0 | 353 | | |
| | 0 | 354 | | // Workflow activation strategies. |
| | 0 | 355 | | .AddScoped<IWorkflowActivationStrategy, SingletonStrategy>() |
| | 0 | 356 | | .AddScoped<IWorkflowActivationStrategy, CorrelatedSingletonStrategy>() |
| | 0 | 357 | | .AddScoped<IWorkflowActivationStrategy, CorrelationStrategy>() |
| | 0 | 358 | | ; |
| | | 359 | | |
| | 0 | 360 | | services.TryAddScoped<IWorkflowDispatchOutbox>(sp => ActivatorUtilities.CreateInstance<WorkflowDispatchOutbox>(s |
| | 0 | 361 | | services.TryAddScoped(WorkflowDispatchOutboxStore); |
| | 0 | 362 | | services.TryAddScoped<IWorkflowDispatchOutboxProcessor, WorkflowDispatchOutboxProcessor>(); |
| | 0 | 363 | | } |
| | | 364 | | |
| | | 365 | | private void RegisterWorkflowTypeAliases(SerializationTypeOptions options) |
| | | 366 | | { |
| | 2 | 367 | | WorkflowRuntimeTypeAliasRegistrar.Register(options, GetRegisteredWorkflowTypes()); |
| | 2 | 368 | | } |
| | | 369 | | |
| | | 370 | | private IEnumerable<Type> GetRegisteredWorkflowTypes() |
| | | 371 | | { |
| | 2 | 372 | | return WorkflowTypes |
| | 7 | 373 | | .Concat(Workflows.Keys.Select(TryResolveWorkflowType).Where(type => type != null).Select(type => type!)) |
| | 2 | 374 | | .Distinct(); |
| | | 375 | | } |
| | | 376 | | |
| | | 377 | | private static Type? TryResolveWorkflowType(string typeName) |
| | | 378 | | { |
| | | 379 | | Type? type; |
| | | 380 | | |
| | | 381 | | try |
| | | 382 | | { |
| | 5 | 383 | | type = Type.GetType(typeName, false); |
| | 5 | 384 | | } |
| | 0 | 385 | | catch (Exception e) when (e is ArgumentException or FileLoadException or FileNotFoundException or TypeLoadExcept |
| | | 386 | | { |
| | 0 | 387 | | return null; |
| | | 388 | | } |
| | | 389 | | |
| | 5 | 390 | | return type != null && typeof(IWorkflow).IsAssignableFrom(type) && type is { IsAbstract: false, IsInterface: fal |
| | 5 | 391 | | ? type |
| | 5 | 392 | | : null; |
| | 0 | 393 | | } |
| | | 394 | | } |