Interface IBackgroundTaskQueue
- Namespace
- Stratara.Abstractions.BackgroundTasks
- Assembly
- Stratara.Abstractions.dll
In-process channel for ad-hoc fire-and-forget work that must outlive the request scope. Consumed by a hosted-service worker; one queue per host.
public interface IBackgroundTaskQueue
- Extension Methods
Remarks
Use for non-critical background tasks (e.g. cleanup, async indexing). For inter-process or durable messaging use ICommandOutboxDispatcher or IMessageBus instead.
Methods
DequeueAsync(CancellationToken)
Dequeue the next task. Blocks asynchronously until one is available or
cancellationToken is signalled. Called by the consumer worker.
ValueTask<(Guid taskId, Func<IServiceProvider, CancellationToken, ValueTask> task)> DequeueAsync(CancellationToken cancellationToken)
Parameters
cancellationTokenCancellationTokenCancels the wait when the host is shutting down.
Returns
- ValueTask<(Guid taskId, Func<IServiceProvider, CancellationToken, ValueTask> task)>
The task id paired with its delegate.
GetTaskInfo(Guid)
Look up status + error info for a previously-enqueued task.
BackgroundTaskInfo? GetTaskInfo(Guid taskId)
Parameters
taskIdGuidThe id returned from QueueTaskAsync(Func<IServiceProvider, CancellationToken, ValueTask>).
Returns
- BackgroundTaskInfo
The current info, or
nullif the task is unknown / already evicted.
QueueTaskAsync(Func<IServiceProvider, CancellationToken, ValueTask>)
Enqueue an asynchronous unit of work. The provided delegate receives a fresh DI scope at execution time.
ValueTask<Guid> QueueTaskAsync(Func<IServiceProvider, CancellationToken, ValueTask> task)
Parameters
taskFunc<IServiceProvider, CancellationToken, ValueTask>The async delegate to execute.
Returns
- ValueTask<Guid>
The id of the queued task — usable with GetTaskInfo(Guid).
UpdateTaskStatus(Guid, BackgroundTaskStatus, string?)
Update the recorded status of a task — called by the consumer worker.
void UpdateTaskStatus(Guid taskId, BackgroundTaskStatus status, string? error = null)
Parameters
taskIdGuidThe task id.
statusBackgroundTaskStatusThe new status.
errorstringOptional error message; required only for Failed.