Class ProcessStatusWait
OptimaJet.Workflow.Core.Runtime.ProcessStatusWait
Acquires exclusive execution access to a process by changing its persisted status to ProcessStatus.Running, waiting and retrying when the process is already being executed.
Namespace: OptimaJet.Workflow.Core.Runtime
public sealed class ProcessStatusWait : IDisposableType Hierarchy
- ProcessStatusWait Current type
- Implemented interfaces
Constructors
public ProcessStatusWait(WorkflowRuntime runtime, Guid processToWaitId, Guid calleeProcessId) #Parameters
runtimeWorkflowRuntimeprocessToWaitIdGuidcalleeProcessIdGuidRemarks
Methods
public Task<bool> LockOrStartWaiting() #Returns
Task<Boolean>Remarks
public Task<bool> LockOrStartWaiting(CancellationToken cancellationToken) #Parameters
cancellationTokenCancellationTokenReturns
Task<Boolean>Remarks
public Task<bool> LockOrStartWaiting(TimeSpan timeout) #Parameters
timeoutTimeSpanReturns
Task<Boolean>Remarks
public Task<bool> LockOrStartWaiting(TimeSpan timeout, CancellationToken cancellationToken) #Parameters
timeoutTimeSpancancellationTokenCancellationTokenReturns
Task<Boolean>Remarks
The first acquisition attempt is immediate. After the first conflict, the method subscribes to runtime status-change notifications and makes another immediate attempt to avoid missing a status change that occurred while the handler was being attached.
A wait is released when the target enters ProcessStatus.Idled, ProcessStatus.Finalized, ProcessStatus.Terminated, or ProcessStatus.Error. The status is then changed to ProcessStatus.Running atomically by the persistence provider; if another contender changes it first, waiting continues.
In multi-server mode, the method waits for either the local runtime event or a persistence polling result. The polling interval is taken from MultiServerSettings.ProcessStatusPollInterval.
The implementation performs up to four wait cycles after the initial conflict and makes a final immediate acquisition attempt. Consequently, the total duration can exceed timeout.
Cancellation ends the current wait without throwing OperationCanceledException. The method still performs its remaining immediate acquisition attempts and can return true if one of them succeeds.
public void Dispose() #Remarks
Remarks
An acquisition attempt succeeds when the persistence provider changes the target process status to ProcessStatus.Running. If the status cannot be changed because another operation is using the process, this class waits until the process enters a non-running status and then tries again.
In a single-server configuration, a retry is triggered by the runtime status-change event. In a multi-server configuration, the persisted status is also polled because the event can be raised on another server. The polling interval is taken from MultiServerSettings.ProcessStatusPollInterval.
This class does not execute the target process and does not restore its status after a successful acquisition. The caller is responsible for completing the protected operation and performing the required subsequent status transition or process deletion.