Interface ILongRunningOperationService
A service for managing long-running operations that can be executed in the background.
Namespace: Umbraco.Cms.Core.Services
Assembly: Umbraco.Core.dll
Syntax
public interface ILongRunningOperationService
Methods
View SourceGetByTypeAsync(string, int, int, LongRunningOperationStatus[]?)
Gets the active long-running operations of a specific type.
Declaration
Task<PagedModel<LongRunningOperation>> GetByTypeAsync(string type, int skip, int take, LongRunningOperationStatus[]? statuses = null)
Parameters
| Type | Name | Description |
|---|---|---|
| string | type | The type of the long-running operation. |
| int | skip | Number of operations to skip. |
| int | take | Number of operations to take. |
| LongRunningOperationStatus[] | statuses | Optional array of statuses to filter the operations by. If null, only enqueued and running operations are returned. |
Returns
| Type | Description |
|---|---|
| Task<PagedModel<LongRunningOperation>> | True if the operation is running or enqueued; otherwise, false. |
GetResultAsync<TResult>(Guid)
Gets the result of a long-running operation.
Declaration
Task<Attempt<TResult?, LongRunningOperationResultStatus>> GetResultAsync<TResult>(Guid operationId)
Parameters
| Type | Name | Description |
|---|---|---|
| Guid | operationId | The unique identifier of the long-running operation. |
Returns
| Type | Description |
|---|---|
| Task<Attempt<TResult, LongRunningOperationResultStatus>> | An Attempt<TResult> containing the result of the operation and its status. If the operation is not found or has not completed, the result will be null. |
Type Parameters
| Name | Description |
|---|---|
| TResult | The type of the result expected from the operation. |
GetStatusAsync(Guid)
Gets the status of a long-running operation by its unique identifier.
Declaration
Task<LongRunningOperationStatus?> GetStatusAsync(Guid operationId)
Parameters
| Type | Name | Description |
|---|---|---|
| Guid | operationId | The unique identifier for the operation. |
Returns
| Type | Description |
|---|---|
| Task<LongRunningOperationStatus?> | True if the operation is running or enqueued; otherwise, false. |
RunAsync(string, Func<CancellationToken, Task>, bool, bool)
Enqueues a long-running operation to be executed in the background.
Declaration
Task<Attempt<Guid, LongRunningOperationEnqueueStatus>> RunAsync(string type, Func<CancellationToken, Task> operation, bool allowConcurrentExecution = false, bool runInBackground = true)
Parameters
| Type | Name | Description |
|---|---|---|
| string | type | The type of the long-running operation, used for categorization. |
| Func<CancellationToken, Task> | operation | The operation to execute, which should accept a System.Threading.CancellationToken. |
| bool | allowConcurrentExecution | Whether to allow multiple instances of the same operation type to run concurrently. |
| bool | runInBackground | Whether to run the operation in the background. |
Returns
| Type | Description |
|---|---|
| Task<Attempt<Guid, LongRunningOperationEnqueueStatus>> | An Attempt<TResult> indicating the status of the enqueue operation. |
Exceptions
| Type | Condition |
|---|---|
| InvalidOperationException | Thrown if attempting to run an operation in the foreground within a scope. |
RunAsync<T>(string, Func<CancellationToken, Task<T>>, bool, bool)
Enqueues a long-running operation to be executed in the background.
Declaration
Task<Attempt<Guid, LongRunningOperationEnqueueStatus>> RunAsync<T>(string type, Func<CancellationToken, Task<T>> operation, bool allowConcurrentExecution = false, bool runInBackground = true)
Parameters
| Type | Name | Description |
|---|---|---|
| string | type | The type of the long-running operation, used for categorization. |
| Func<CancellationToken, Task<T>> | operation | The operation to execute, which should accept a System.Threading.CancellationToken. |
| bool | allowConcurrentExecution | Whether to allow multiple instances of the same operation type to run concurrently. |
| bool | runInBackground | Whether to run the operation in the background. |
Returns
| Type | Description |
|---|---|
| Task<Attempt<Guid, LongRunningOperationEnqueueStatus>> | An Attempt<TResult> indicating the status of the enqueue operation. |
Type Parameters
| Name | Description |
|---|---|
| T | The type of the result expected from the operation. |
Exceptions
| Type | Condition |
|---|---|
| InvalidOperationException | Thrown if attempting to run an operation in the foreground within a scope. |