Assembly: OptimaJet.Workflow.Core

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.

public sealed class ProcessStatusWait : IDisposable

Type Hierarchy

  • ProcessStatusWait Current type

Constructors

public ProcessStatusWait(WorkflowRuntime runtime, Guid processToWaitId, Guid calleeProcessId) #
Initializes a coordinator that can acquire execution access to the target process on behalf of another process.

Parameters

Name
Type
Description
runtime
WorkflowRuntime
The workflow runtime whose persistence provider and status-change notifications are used.
processToWaitId
Guid
The identifier of the target process whose status must be changed to ProcessStatus.Running.
calleeProcessId
Guid
The identifier of the process on whose behalf execution access to the target process is requested.

Remarks

Construction does not access persistence or subscribe to runtime events. Acquisition starts when a ProcessStatusWait.LockOrStartWaiting(TimeSpan, CancellationToken) overload is called.

Methods

public Task<bool> LockOrStartWaiting() #
Attempts to acquire execution access to the target process, using 30 seconds as the timeout for each wait cycle.

Returns

Type
Description
Task<Boolean>
true if the target process status was changed to ProcessStatus.Running; false if the process does not have a defined status or access could not be acquired within the retry budget.

Remarks

The 30-second timeout applies separately to each wait cycle, not to the entire operation.
public Task<bool> LockOrStartWaiting(CancellationToken cancellationToken) #
Attempts to acquire execution access to the target process, waiting without a timeout until a status change is detected or the provided token cancels the current wait.

Parameters

Name
Type
Description
cancellationToken
CancellationToken
A token that stops an in-progress wait between acquisition attempts. It is not passed to persistence operations.

Returns

Type
Description
Task<Boolean>
true if the target process status was changed to ProcessStatus.Running; false if the process does not have a defined status or access could not be acquired within the retry budget.

Remarks

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 Task<bool> LockOrStartWaiting(TimeSpan timeout) #
Attempts to acquire execution access to the target process, using the specified timeout for each wait cycle.

Parameters

Name
Type
Description
timeout
TimeSpan
The maximum duration of each wait for a status-change notification or persistence polling result. Specify Timeout.InfiniteTimeSpan to wait without a timeout.

Returns

Type
Description
Task<Boolean>
true if the target process status was changed to ProcessStatus.Running; false if the process does not have a defined status or access could not be acquired within the retry budget.

Remarks

The timeout applies separately to each wait cycle, not to the entire operation.
public Task<bool> LockOrStartWaiting(TimeSpan timeout, CancellationToken cancellationToken) #
Attempts to acquire execution access to the target process by changing its persisted status to ProcessStatus.Running, waiting and retrying while another operation is executing the process.

Parameters

Name
Type
Description
timeout
TimeSpan
The maximum duration of each wait for a status-change notification or persistence polling result. This is not an overall timeout. Specify Timeout.InfiniteTimeSpan to wait without a timeout.
cancellationToken
CancellationToken
A token that stops an in-progress wait between acquisition attempts. It is not passed to persistence operations.

Returns

Type
Description
Task<Boolean>
true if the target process status was changed to ProcessStatus.Running, and the caller may proceed with the protected operation; false if the process does not have a defined status or access could not be acquired within the retry budget.

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() #
Stops this instance from receiving runtime status-change notifications and releases its waiting resources.

Remarks

This method does not change the target process status and therefore does not release execution access acquired by ProcessStatusWait.LockOrStartWaiting(TimeSpan, CancellationToken). The caller remains responsible for the target process's subsequent status transition or deletion.

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.