feature/queue-health-metrics-and-schema
File: src/health/health.controller.ts
- Added
GET /health/queuesendpoint - Returns
QueueHealthResponseDtowith:- Overall system health status (healthy/degraded/unhealthy)
- Per-queue health metrics including job counts and failure rates
- System-wide failure rate
- Timestamp of health check
File: src/queue/queue-health.service.ts
getQueueHealth()method calculates health for all queues- Determines health status based on:
- Failure rate > 20% → unhealthy
- Failure rate > 10% → degraded
- Otherwise → healthy
- Tracks job counts: waiting, active, completed, failed, delayed, prioritized
- Calculates average retry count and failure rate per queue
File: src/queue/dtos/queue-stats.dto.ts
Created comprehensive DTOs with full Swagger documentation:
- Fields: waiting, active, completed, failed, delayed, prioritized
- Usage: Represents job counts in each state
- Fields: queue name, status, jobs, totalJobs, failureRate, avgRetryCount, timestamp
- Usage: Individual queue health snapshot
- Fields: status, queues[], totalJobsAcrossQueues, systemWideFailureRate, timestamp
- Usage: Response for
/health/queuesendpoint
- Fields: queue, jobCounts, totalProcessed, successCount, failureCount, failureRate, avgProcessingTimeSeconds, avgRetryCount, failureReasonCounts, timestamp
- Usage: Detailed statistics for a single queue
- Fields: queues[], timestamp
- Usage: Response for
/health/queues/statisticsendpoint
File: src/queue/retry-backoff-config.service.ts
Provides centralized management of retry and backoff strategies:
- Per-Queue Configuration: Each queue has its own default retry settings
- Environment Variable Overrides:
RETRY_BACKOFF_{QUEUE}_ATTEMPTS,RETRY_BACKOFF_{QUEUE}_DELAY_MS,RETRY_BACKOFF_{QUEUE}_MULTIPLIER - Default Configurations:
- clip-generation: 5 attempts, 2000ms exponential backoff
- nft-mint: 3 attempts, 1000ms exponential backoff
- clip-posting: 4 attempts, 1500ms exponential backoff
- email-delivery: 3 attempts, 1000ms exponential backoff
- anomaly-detection: 3 attempts, 2000ms exponential backoff
getRetryConfig(queueName)- Get config for specific queuegetBullMQRetryConfig(queueName)- Get BullMQ-compatible formatgetAllRetryConfigs()- Get all queue configurationsgetMaxTotalJobTimeMs(queueName)- Calculate max retry durationgetRetryInfo(queueName)- Get detailed retry information with breakdown per attempt
Returns health metrics for all BullMQ queues
- Response:
QueueHealthResponseDto - Status Codes:
- 200: All queues healthy
- 503: One or more queues unhealthy
- Example Response:
{
"status": "healthy",
"queues": [
{
"queue": "clip-generation",
"status": "healthy",
"jobs": {
"waiting": 10,
"active": 2,
"completed": 150,
"failed": 5,
"delayed": 3,
"prioritized": 1
},
"totalJobs": 171,
"failureRate": 3.2,
"avgRetryCount": 1.2,
"timestamp": "2026-06-27T10:30:45.123Z"
}
],
"totalJobsAcrossQueues": 500,
"systemWideFailureRate": 2.8,
"timestamp": "2026-06-27T10:30:45.123Z"
}Returns detailed statistics for all queues
- Response:
QueueStatisticsResponseDto - Status Code: 200
- Includes:
- Job counts by state
- Success/failure counts
- Average processing time in seconds
- Failure reasons breakdown
- Failure rate percentage
- Added imports:
QueueModule - Added providers:
QueueHealthService,RetryBackoffConfigService - Added exports:
QueueHealthService,RetryBackoffConfigService
- Added providers:
RetryBackoffConfigService,QueueHealthService - Added exports:
RetryBackoffConfigService,QueueHealthService
- Injects
QueueHealthService - New endpoints leverage existing Swagger documentation patterns
- Error handling with appropriate HTTP status codes
- No breaking changes to existing queue services
RetryBackoffConfigServicecan be injected into any service needing retry configurationQueueHealthServicemonitors all registered queues
RETRY_BACKOFF_CLIP_GENERATION_ATTEMPTS=5
RETRY_BACKOFF_CLIP_GENERATION_DELAY_MS=2000
RETRY_BACKOFF_CLIP_GENERATION_MULTIPLIER=2
RETRY_BACKOFF_NFT_MINT_ATTEMPTS=3
RETRY_BACKOFF_NFT_MINT_DELAY_MS=1000
RETRY_BACKOFF_NFT_MINT_MULTIPLIER=2
# ... and so on for other queues
src/queue/dtos/queue-stats.dto.ts- API response schemassrc/queue/retry-backoff-config.service.ts- Centralized retry configurationsrc/queue/queue-health.service.ts- Queue health metrics service
src/health/health.controller.ts- Added two new endpointssrc/health/health.module.ts- Updated module imports/exports/providerssrc/queue/queue.module.ts- Updated module providers/exports
- Run
npm run buildto compile and verify no TypeScript errors - Run
npm run testto ensure no regressions - Test the new endpoints:
curl http://localhost:3000/health/queuescurl http://localhost:3000/health/queues/statistics
- Verify Swagger documentation updated automatically
- Commit and push to create PR
- Service Separation: Health metrics in separate service for maintainability
- Centralized Configuration: All retry logic in one place for consistency
- Environment Variable Support: Allows ops teams to tune without code changes
- Graceful Degradation: Health checks handle unavailable queues gracefully
- Comprehensive DTOs: All Swagger documentation included for API clarity