Skip to content

Comments

refactor(importer): decompose service into focused sub-packages#175

Merged
javi11 merged 1 commit intomainfrom
refactor/importer-decomposition-phase3
Dec 28, 2025
Merged

refactor(importer): decompose service into focused sub-packages#175
javi11 merged 1 commit intomainfrom
refactor/importer-decomposition-phase3

Conversation

@javi11
Copy link
Owner

@javi11 javi11 commented Dec 28, 2025

Summary

  • Extract the 1700+ line importer service into a thin facade delegating to specialized sub-services
  • Create queue/ package for worker pool management with exponential backoff retry (Manager, Claimer)
  • Create scanner/ package for directory scanning and NZBDav imports (DirectoryScanner, NzbDavImporter)
  • Create postprocessor/ package for post-import processing coordination (Coordinator orchestrating symlinks, STRM files, VFS notifications, health scheduling, ARR notifications)
  • Reduce service.go from ~1700 to ~930 lines (~45% reduction) while maintaining backward compatibility via type aliases

Test plan

  • Verify build passes: go build ./...
  • Verify all tests pass: go test ./internal/importer/...
  • Test manual directory scanning functionality
  • Test NZBDav import functionality
  • Test queue processing with pause/resume
  • Verify post-processing (symlinks, STRM files, VFS notifications) works correctly

🤖 Generated with Claude Code

Extract the 1700+ line importer service into a thin facade delegating to
specialized sub-services:

**New packages:**
- `queue/`: Worker pool management with exponential backoff retry
  - Manager: Start/Stop/Pause/Resume worker lifecycle
  - Claimer: Item claiming with database contention handling
- `scanner/`: Directory scanning and NZBDav imports
  - DirectoryScanner: Manual directory scanning for NZB/STRM files
  - NzbDavImporter: Bulk import from NZBDav databases
- `postprocessor/`: Post-import processing coordination
  - Coordinator: Orchestrates symlinks, STRM files, VFS notifications,
    health scheduling, and ARR notifications

**Changes to service.go:**
- Reduced from ~1700 to ~930 lines (~45% reduction)
- Service now delegates to queueManager, dirScanner, nzbdavImporter
- Implements queue.ItemProcessor interface for processing callbacks
- Type aliases maintain backward compatibility (ScanStatus, ImportInfo, etc.)
- Adapter types bridge Service to sub-service interfaces

**Benefits:**
- Single responsibility: each package has one clear purpose
- Testability: sub-services can be tested in isolation
- Maintainability: smaller, focused files are easier to understand
- Extensibility: new features can be added without touching core service

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@javi11 javi11 merged commit e701b85 into main Dec 28, 2025
1 check passed
@javi11 javi11 deleted the refactor/importer-decomposition-phase3 branch February 4, 2026 13:41
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.

1 participant