Class BackgroundDeletionService

Assembly: redb.Core.dll

Background deletion service with queue-based processing.
Implements IHostedService for background task execution.
Uses Channel for thread-safe task queue.
Each purge runs in separate DI scope with its own DB connection.
Progress is stored in trash object in database (no memory cache).
CLUSTER-SAFE: Recovers orphaned tasks at startup with atomic claiming.

public class BackgroundDeletionService : BackgroundService, IHostedService, IDisposable, IBackgroundDeletionService

Inheritance

ObjectBackgroundServiceBackgroundDeletionService

Implements

Properties

QueueLength

Number of pending tasks in queue.

public int QueueLength { get; }

Methods

DeleteAsync(IEnumerable<long>, IRedbUser, int, long?)

Mark objects for deletion and enqueue background purge.

public Task<DeletionMark> DeleteAsync(IEnumerable<long> objectIds, IRedbUser user, int batchSize = 10, long? trashParentId = null)

EnqueuePurge(long, int, long, int)

Enqueue purge for an existing trash container.

public void EnqueuePurge(long trashId, int totalCount, long userId, int batchSize = 10)

ExecuteAsync(CancellationToken)

Background task processor - reads from queue and executes purges.

protected override Task ExecuteAsync(CancellationToken stoppingToken)

GetProgressAsync(long)

Get current progress for a trash container from database.

public Task<PurgeProgress?> GetProgressAsync(long trashId)

GetUserActiveProgressAsync(long)

Get all active deletions for a user from database.

public Task<List<PurgeProgress>> GetUserActiveProgressAsync(long userId)

Constructors