| | | 1 | | using Elsa.Workflows.Runtime.Services; |
| | | 2 | | using Microsoft.Extensions.Hosting; |
| | | 3 | | using Microsoft.Extensions.Logging; |
| | | 4 | | |
| | | 5 | | namespace Elsa.Workflows.Runtime.HostedServices; |
| | | 6 | | |
| | | 7 | | /// <summary> |
| | | 8 | | /// Subscribes to <see cref="IHostApplicationLifetime.ApplicationStopping"/> and runs the drain orchestrator on |
| | | 9 | | /// host stop. Registered AFTER <c>InstanceHeartbeatService</c> so that <see cref="IHostedService.StopAsync"/> |
| | | 10 | | /// runs in reverse order — drain first, heartbeat last (research R5 / FR-029). |
| | | 11 | | /// </summary> |
| | 7 | 12 | | public sealed class DrainOrchestratorHostedService( |
| | 7 | 13 | | IDrainOrchestrator orchestrator, |
| | 7 | 14 | | ILogger<DrainOrchestratorHostedService> logger) : IHostedService |
| | | 15 | | { |
| | | 16 | | /// <inheritdoc /> |
| | 7 | 17 | | public Task StartAsync(CancellationToken cancellationToken) => Task.CompletedTask; |
| | | 18 | | |
| | | 19 | | /// <inheritdoc /> |
| | | 20 | | public Task StopAsync(CancellationToken cancellationToken) => |
| | 10 | 21 | | DrainTriggerExecutor.RunAsync(orchestrator, DrainTrigger.HostStopSignal, logger, "Graceful drain", cancellationT |
| | | 22 | | } |