1.5 KiB
1.5 KiB
ADR-0024: Background Job Scheduler
Status
Accepted
Context
The platform needs background job processing for:
- Periodic tasks (cron jobs)
- Asynchronous processing
- Long-running operations
- Retry logic for failed jobs
Options considered:
- asynq (Redis-based) - Simple, feature-rich
- cron + custom queue - Build our own
- Kafka consumers - Use event bus
- External service - AWS SQS, etc.
Decision
Use asynq (Redis-backed) for job scheduling:
- Cron jobs:
github.com/robfig/cron/v3for periodic tasks - Job queue:
github.com/hibiken/asynqfor async jobs - Storage: Redis (shared with cache)
- Features: Retries, backoff, job status tracking
Rationale:
- Simple, Redis-backed (no new infrastructure)
- Good Go library support
- Built-in retry and backoff
- Job status tracking
- Easy to integrate
- Can scale horizontally (multiple workers)
Consequences
Positive
- Simple (uses existing Redis)
- Feature-rich (retries, backoff)
- Good performance
- Easy to scale
- Job status tracking
Negative
- Tied to Redis (but we're already using it)
- Requires Redis to be available
Implementation Notes
- Install:
github.com/hibiken/asynqandgithub.com/robfig/cron/v3 - Create
pkg/scheduler/scheduler.gointerface - Implement
internal/infra/scheduler/asynq_scheduler.go - Register jobs in
internal/infra/scheduler/job_registry.go - Start worker in fx lifecycle
- Configure retry policies (exponential backoff)
- Add job monitoring endpoint