| | | 1 | | using CShells.Lifecycle; |
| | | 2 | | using Elsa.Workflows.Runtime.Options; |
| | | 3 | | using Elsa.Workflows.Runtime.Services; |
| | | 4 | | |
| | | 5 | | namespace Elsa.Workflows.Runtime.Lifecycle; |
| | | 6 | | |
| | | 7 | | /// <summary> |
| | | 8 | | /// CShells <see cref="IShellInitializer"/> that re-applies any persisted administrative pause state when a shell |
| | | 9 | | /// is activated. Without this hook, a shell configured for <see cref="PausePersistencePolicy.AcrossReactivations"/> |
| | | 10 | | /// pause persistence would write the persisted key on pause but never read it on subsequent reactivations — meaning |
| | | 11 | | /// the runtime would resume dispatching even though an operator had explicitly paused it before the previous |
| | | 12 | | /// shell tear-down. |
| | | 13 | | /// </summary> |
| | | 14 | | /// <remarks> |
| | | 15 | | /// <para> |
| | | 16 | | /// This is the shell-aware counterpart of <c>InitializePauseStateStartupTask</c> (used by IModule consumers). |
| | | 17 | | /// Both call <see cref="QuiescenceSignal.InitializePersistedStateAsync"/>, but they fire at different lifecycle |
| | | 18 | | /// points: |
| | | 19 | | /// </para> |
| | | 20 | | /// <list type="bullet"> |
| | | 21 | | /// <item> |
| | | 22 | | /// <description> |
| | | 23 | | /// <c>IStartupTask</c> runs once when the IModule host starts up. Correct for non-shell deployments, |
| | | 24 | | /// but in a shell-aware deployment a shell can be activated and reactivated independently of the host — |
| | | 25 | | /// the startup task only fires for the FIRST activation. |
| | | 26 | | /// </description> |
| | | 27 | | /// </item> |
| | | 28 | | /// <item> |
| | | 29 | | /// <description> |
| | | 30 | | /// <see cref="IShellInitializer"/> runs on EVERY shell activation, including reactivations after a reload. |
| | | 31 | | /// This is what FR-028 requires: pause state survives every shell reactivation, not just the first. |
| | | 32 | | /// </description> |
| | | 33 | | /// </item> |
| | | 34 | | /// </list> |
| | | 35 | | /// </remarks> |
| | 0 | 36 | | public sealed class InitializePauseStateShellInitializer(IQuiescenceSignal signal) : IShellInitializer |
| | | 37 | | { |
| | | 38 | | /// <inheritdoc /> |
| | | 39 | | public Task InitializeAsync(CancellationToken cancellationToken = default) => |
| | 0 | 40 | | signal.InitializePersistedStateAsync(cancellationToken).AsTask(); |
| | | 41 | | } |