Path: redb/redb.Core/Services/IBackgroundDeletionService.cs Snapshot: redb, development snapshot 2026-12-06. This is the development state of the public mirrors; it may differ from the published packages. License: Apache-2.0. Repository: https://github.com/redbase-app/redb Page: https://redbase.app/src/dev-2026-12-06/redb/redb.Core/Services/IBackgroundDeletionService.cs ---- using System; using System.Collections.Generic; using System.Threading.Tasks; using redb.Core.Models.Contracts; namespace redb.Core.Services; /// /// Background deletion service. Fire-and-forget delete: callers mark objects, return /// immediately, and a polling worker physically purges the trash on a separate DB /// connection. State of truth lives entirely in _objects rows (trash containers /// with _value_string='pending') — the worker drives off DB polling, so a /// worker crash or force-kill leaves no in-memory state to recover from. /// public interface IBackgroundDeletionService { /// /// Mark objects for deletion. Returns once /// has re-parented the objects under the trash scheme — they disappear from regular /// queries immediately. The physical purge of the _values cascade runs in /// the next worker poll cycle. /// Task DeleteAsync( IEnumerable objectIds, IRedbUser user, int batchSize = 10, long? trashParentId = null); /// /// No-op in the DB-polling design. Kept on the interface so callers that did a /// manual SoftDeleteAsync + EnqueuePurge handshake don't break — the /// trash row they wrote is picked up by the worker's next poll cycle on its own. /// void EnqueuePurge(long trashId, int totalCount, long userId, int batchSize = 10); /// /// Get current progress for a trash container from database. /// Returns null if trash container not found or already deleted. /// Task GetProgressAsync(long trashId); /// /// Get all active (pending/running) deletions for a user from database. /// Task> GetUserActiveProgressAsync(long userId); /// /// Always 0 in the DB-polling design — there is no in-memory queue. Callers who /// want the actual count of pending trash containers should query the DB directly /// (see IObjectStorageProvider.GetOrphanedDeletionTasksAsync). /// int QueueLength { get; } } /// /// Result of marking objects for deletion. /// /// ID of the created trash container object /// Number of objects marked for deletion (including descendants) public record DeletionMark(long TrashId, int MarkedCount); /// /// Progress of trash purge operation. /// /// ID of the trash container being purged /// Number of objects already deleted /// Number of objects still remaining /// Current status of the purge operation /// When the purge operation started /// ID of the user who initiated the deletion public record PurgeProgress( long TrashId, int Deleted, int Remaining, PurgeStatus Status, DateTimeOffset StartedAt, long UserId) { /// /// Total number of objects to delete. /// public int Total => Deleted + Remaining; /// /// Whether the purge operation is complete. /// public bool IsCompleted => Status == PurgeStatus.Completed; } /// /// Status of a purge operation. /// public enum PurgeStatus { /// Objects marked for deletion, purge not started yet Pending, /// Purge is in progress Running, /// Purge completed successfully Completed, /// Purge failed with error Failed, /// Purge was cancelled Cancelled } /// /// Orphaned deletion task found at startup. /// Used for cluster-safe recovery of incomplete deletions. /// /// ID of the trash container /// Total objects to delete /// Already deleted count /// Current status /// User who initiated the deletion public record OrphanedTask(long TrashId, int Total, int Deleted, string Status, long OwnerId);