mirror of
https://github.com/azaion/satellite-provider.git
synced 2026-06-21 15:01:14 +00:00
b0fffa6d42
Phase A baseline outputs from /autodev (Steps 1-5): - Problem & solution docs (_docs/00_problem, _docs/01_solution) - Codebase documentation (_docs/02_document) incl. architecture, module-layout, glossary, system-flows, baseline compliance scan - Test specs (blackbox, performance, resilience, security, resource, traceability matrix) - Test task decomposition (_docs/02_tasks/todo): AZ-285..AZ-290 - Testability refactor (_docs/04_refactoring/01-testability-refactoring): - TC-01 Move DownloadedTileInfoV2 + new ExistingTileInfo to Common.DTO - TC-02 Replace dead ISatelliteDownloader API with real signatures - TC-03 GoogleMapsDownloaderV2 implements ISatelliteDownloader - TC-04 TileService depends on ISatelliteDownloader (mockable) - TC-05 DI + endpoints use ISatelliteDownloader - Test runner scripts (scripts/run-tests.sh, run-performance-tests.sh) - Autodev state pointer (_docs/_autodev_state.md) Prepares the codebase for AZ-285..AZ-290 unit/integration test work. Co-authored-by: Cursor <cursoragent@cursor.com>
3.8 KiB
3.8 KiB
Module: Services/RegionService + RegionProcessingService + RegionRequestQueue
Purpose
End-to-end region processing pipeline: API request handling → queue → background worker → tile download → output file generation. Three closely coupled classes form the region processing subsystem.
Public Interface
RegionService (implements IRegionService)
RequestRegionAsync(...): createsRegionEntitywith status "queued", enqueues aRegionRequest, returnsRegionStatusGetRegionStatusAsync(Guid id): reads region record and maps toRegionStatusProcessRegionAsync(Guid id, CancellationToken): the main processing pipeline — see Internal Logic
RegionProcessingService (BackgroundService)
ExecuteAsync(CancellationToken): spawnsMaxConcurrentRegionsparallel worker tasks, each in an infinite dequeue loop
RegionRequestQueue (implements IRegionRequestQueue)
EnqueueAsync(RegionRequest, CancellationToken): writes to a boundedChannel<RegionRequest>DequeueAsync(CancellationToken): reads from the channel (blocks until available)Count: current queue depth
Internal Logic
RegionService.ProcessRegionAsync
- Sets region status to "processing"
- Creates a 5-minute timeout
CancellationTokenSource - Queries existing tiles in the region
- Calls
TileService.DownloadAndStoreTilesAsyncto fetch missing tiles - Counts downloaded vs reused tiles
- Generates CSV file (
region_{id}_ready.csv) listing tile coordinates + paths - Optionally stitches tiles into a single JPEG image (if
StitchTilesis true) - Generates summary file (
region_{id}_summary.txt) - Updates region status to "completed"
- On any error: sets status to "failed", generates error summary
Tile Stitching
Uses ImageSharp to:
- Compute a tile grid from tile coordinates
- Create a new image of
(gridWidth × 256) × (gridHeight × 256)pixels - Place each tile image at its grid position
- Draw a red crosshair at the center coordinates
- Save as JPEG
Error Handling
Comprehensive catch blocks for:
TaskCanceledException(timeout vs external cancellation)OperationCanceledExceptionRateLimitException(Google rate limiting)HttpRequestException(with status code)- Generic
ExceptionEach sets status to "failed" and writes an error summary file.
RegionProcessingService
- Spawns
MaxConcurrentRegionsworker tasks with staggered startup (100–500ms random delay) - Each worker loops: dequeue →
ProcessRegionAsync→ repeat - Graceful shutdown on cancellation
RegionRequestQueue
- Uses
System.Threading.Channels.Channel<T>.CreateBoundedwithBoundedChannelFullMode.Wait - Tracks
_totalEnqueuedand_totalDequeuedcounters
Dependencies
ITileService,IRegionRepository,IRegionRequestQueueStorageConfig,ProcessingConfigSixLabors.ImageSharp— tile stitchingSatelliteProvider.Common.Utils.GeoUtils— coordinate conversion for stitching
Consumers
Program.csAPI endpoints —RequestRegionAsync,GetRegionStatusAsyncRouteService—RequestRegionAsync(for geofence regions)RouteProcessingService—RequestRegionAsync(for route-point regions)
Data Models
- Input:
RegionRequest(queue message) - Output:
RegionStatus(API response), CSV files, summary files, stitched images - Persistence:
RegionEntity
Configuration
StorageConfig.ReadyDirectory— output file locationProcessingConfig.MaxConcurrentRegions— worker countProcessingConfig.QueueCapacity— bounded channel size
External Integrations
- PostgreSQL (via repositories)
- File system (CSV, summary, stitched images in
./ready/) - Google Maps (indirectly via TileService → GoogleMapsDownloaderV2)
Security
None.
Tests
Integration tests in RegionTests.cs cover the request → poll → complete flow.