Skip to main content
Table of Contents

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

cancellationToken CancellationToken

Cancels 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

taskId Guid

The id returned from QueueTaskAsync(Func<IServiceProvider, CancellationToken, ValueTask>).

Returns

BackgroundTaskInfo

The current info, or null if 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

task Func<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

taskId Guid

The task id.

status BackgroundTaskStatus

The new status.

error string

Optional error message; required only for Failed.