Phase 3 integration: enqueue via RabbitMQ and execute jobs with downloader-backed workers#6
Conversation
Review Fixes Before Merge — Async Download Execution FlowI reviewed the current PR changes. The overall direction is correct:
Before merging, apply the following fixes. IMPORTANT: Do NOT start:
1. Verify and complete RabbitMQ consumer flowThe intended architecture must be: API: HTTP Request Worker: RabbitMQ Consumer Verify that If consumer wiring is incomplete:
Do not leave worker pool running without queue consumption. 2. Move media item creation out of worker executionCurrent behavior: Worker creates media items when none exist. Example: Worker receives job This mixes business creation logic with execution logic. Change responsibility: Job/API service should handle: Create Job Worker should only: Consume Message Remove automatic media item creation from worker processTask flow. If existing flow requires temporary fallback behavior, add a TODO explaining migration path instead of silently creating entities. 3. Validate worker lifecycle statesEnsure job lifecycle remains consistent: Expected flow: PENDING Verify:
Do not add new progress features yet. 4. Review queue publish failure handlingScenario:
Current state must not become inconsistent. Handle this case:
Do not leave jobs permanently stuck in PENDING without a queue message. 5. Verify Redis nil safetyReview all worker paths using Redis. Ensure no panic occurs when Redis is unavailable. Check patterns like: if redis != nil {
...
}
Apply consistently where required.
6. Keep repository/schema changes focused
The media_items size column alignment is correct.
Keep:
size_bytes -> size
changes only where required.
Do not perform unrelated database cleanup.
7. Testing
After changes run:
go test ./...
golangci-lint run ./...
go build ./...
Add/update tests for:
queue dispatch flow
worker processing with downloader mock
failure handling
Avoid tests requiring:
external services
YouTube network access
real RabbitMQ unless marked integration.
Before finishing provide:
Files changed
Architecture flow after changes
Tests executed
Any remaining technical debt
Suggested commit:
fix(worker): improve async download execution flow |
Implemented ✅
Tests run:
Added focused tests:
Remaining technical debt:
|
This PR advances the current Phase 3 gap by replacing in-process job submission/processing shortcuts with the intended async flow. API-created jobs now enter RabbitMQ, and workers execute media items through the downloader abstraction with persisted job/item progress updates.
API → Queue boundary (source of truth for async dispatch)
POST /jobsnow publishes aqueue.Messageto RabbitMQ instead of submitting directly to the in-process worker channel.queue.Servicefor dispatch.Worker execution path (remove simulated processing)
downloader.Downloaderdependency and runs real item execution viaDownload(...).source_urlwhen none exists, updates per-item status/size, and drives job lifecycle states (PROCESSING→COMPLETED/FAILED).Jobs service internal accessors for background workers
GetJobInternal,GetMediaItemsInternal) to avoid auth-bound APIs in background execution.UpdateMediaItemSizepassthrough for worker result persistence.Schema/repository alignment
media_items.size(instead ofsize_bytes) in select/return/update queries.