26ff8d9b4f
Set up repository with legacy .NET Framework 4.8 source (OLD/), new .NET 10 Blazor solution (NEW/), OpenSpec specifications, documentation, and project configuration.
3.3 KiB
3.3 KiB
Implement Data Sync Service
Summary
Implement the background data synchronization service as a .NET BackgroundService that maintains the local SQL Server cache by fetching data from JDE (Oracle) and CMS (Sybase) source systems on configurable schedules.
Scope
In Scope
DataSyncServiceinheriting fromBackgroundServicewith proper lifecycle managementIDataFetcher<T>interface and fetcher implementations for each table typeDataSyncOptionsandDataSourceConfigstrongly-typed configuration classes- Schedule-based triggering (Mass/Daily/Hourly) with interval checking
- Staging table management with MERGE operations for upserts
DataUpdatelogging for audit trail and recovery- Health checks exposing sync status via ASP.NET Core health check framework
- Telemetry via
System.Diagnostics.MetricsandActivitySource AddDataSyncextension method for DI registration
Out of Scope
- Admin API for manual archive sync triggering (separate change)
- Circuit breaker implementation for CMS (can be added later)
- Periodic index maintenance (separate change)
- Actual JDE/CMS database connectivity (will use mock fetchers initially)
Motivation
The legacy UpdateProcessor runs as a Topshelf Windows service with reflection-based data fetchers and global temp tables. The new implementation uses modern .NET patterns:
BackgroundServicefor proper ASP.NET Core hosting integrationIDataFetcher<T>interfaces for type-safe, testable data retrievalParallel.ForEachAsyncfor cancellation-aware parallel execution- Local temp tables with unique suffixes for parallel isolation
IOptions<T>pattern for strongly-typed configuration
Acceptance Criteria
DataSyncServicestarts with the host and respectsCancellationTokenfor graceful shutdown- Service checks schedules and queues sync tasks based on
LastDataUpdatestimestamps - Sync operations execute in parallel with configurable
MaxDegreeOfParallelism - Each sync creates staging tables, bulk copies data, and executes MERGE operations
- All sync operations are logged to
DataUpdatetable with proper start/end/success tracking - Interrupted syncs are marked as failed at startup via
CloseOpenUpdateEntries() - Health check reports sync status (Healthy/Degraded/Unhealthy) based on interval compliance
- Metrics emitted for operations started/completed/failed and duration histograms
openspec validate implement-data-sync --strictpasses
Dependencies
migrate-database-schema- DataUpdate table and related schema must existdata-accessspec - Repository patterns for database operations
Risks
| Risk | Mitigation |
|---|---|
| Complex parallel execution | Use Parallel.ForEachAsync with proper scoping; local temp tables with unique suffixes |
| Schedule calculation edge cases | Comprehensive unit tests for schedule checking logic |
| Memory pressure from large datasets | IAsyncEnumerable<T> streaming with batched bulk copy |
| Staging table conflicts | Unique _{OperationId} suffix on all temp tables |
Related Specs
data-sync- Core specification for sync behavior and schedulesdomain-models- Entity definitions for synced datadatabase-schema- Table structures and DataUpdate table