Skip to content

Conversation

gentledepp
Copy link
Contributor

fixes #1349

Summary: Batch Cleanup Service Implementation

What We Implemented

New Batch Cleanup Service - A comprehensive solution to automatically manage and clean up expired batch directories that can accumulate from failed sync sessions and network interruptions.

Key Components Added

  1. Core Service Infrastructure
  • IBatchCleanupService - Interface defining cleanup operations
  • BatchCleanupService - Default implementation with robust error handling
  • 486 comprehensive unit tests covering all scenarios and edge cases
  1. Directory Naming Standardization
  • Changed BatchInfo directory format from yyyy_MM_dd_ss to yyyyMMddHHmm
  • Added explanatory comments in code explaining the importance of this format for cleanup service
  1. SyncOptions Configuration
  • BatchRetentionPeriod - Configurable retention period (default: 1 hour)
  • BatchCleanupWhenSessionEnds - Option for immediate vs deferred cleanup (default: false)
  1. Automatic Integration
  • LocalOrchestrator & RemoteOrchestrator - Auto-cleanup on session start
  • WebServerAgent - Dependency injection support for web scenarios
  • DependencyInjection - Service registration for ASP.NET Core applications

How It Improves Batch Cleanup

Prevents Disk Space Issues

  • Automatically removes orphaned batch directories from failed sync sessions
  • Configurable retention periods prevent indefinite accumulation
  • Robust timestamp-based identification of expired batches

Production-Ready Reliability

  • Graceful error handling - Individual directory cleanup failures don't break the entire operation
  • Cancellation support - Respects CancellationToken for clean shutdowns
  • Input validation - Throws meaningful ArgumentExceptions for invalid parameters
  • Non-blocking - Continues cleanup even if some directories are locked or inaccessible

Flexible Configuration

  • Multiple overloads - Works with SyncOptions or direct parameters
  • Override support - Can override configured retention period per operation
  • Inspection capabilities - GetExpiredBatchDirectoriesAsync for audit/monitoring without cleanup
  • Zero retention period - Disables time-based cleanup when set to TimeSpan.Zero

Smart Directory Recognition

  • Format validation - Only processes directories matching yyyyMMddHHmm* pattern
  • Boundary handling - Correctly handles edge cases at cutoff timestamps (≤ comparison)
  • Ordering - Returns expired directories in chronological order for predictable cleanup

Seamless Integration

  • Automatic activation - No code changes needed, runs automatically on sync session start
  • DI-friendly - Full dependency injection support for web applications
  • Backward compatible - Doesn't affect existing sync functionality

This implementation provides a complete, production-ready solution for managing batch directory lifecycle, preventing disk space issues while maintaining sync performance and reliability.

@gentledepp gentledepp force-pushed the feature/1349_batchcleanup branch from eb8af31 to 0b0bea3 Compare September 25, 2025 09:47
@gentledepp gentledepp force-pushed the feature/1349_batchcleanup branch from 0b0bea3 to 026ae70 Compare September 25, 2025 09:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Batch Cleanup Reliability Enhancement

1 participant