feat: add Valkey integration for task queue (closes #98)
- Add ioredis package dependency for Redis-compatible operations - Create ValkeyModule as global NestJS module - Implement ValkeyService with task queue operations: - enqueue(task): Add tasks to FIFO queue - dequeue(): Get next task and update to PROCESSING status - getStatus(taskId): Retrieve task metadata and status - updateStatus(taskId, status): Update task state (COMPLETED/FAILED) - getQueueLength(): Monitor queue depth - clearQueue(): Queue management utility - healthCheck(): Verify Valkey connectivity - Add TaskDto, EnqueueTaskDto, UpdateTaskStatusDto interfaces - Implement TaskStatus enum (PENDING/PROCESSING/COMPLETED/FAILED) - Add comprehensive test suite with in-memory Redis mock (20 tests) - Integrate ValkeyModule into app.module.ts - Valkey Docker Compose service already configured in docker-compose.yml - VALKEY_URL environment variable already in .env.example - Add detailed README with usage examples and API documentation Technical Details: - Uses FIFO queue (RPUSH/LPOP for strict ordering) - Task metadata stored with 24-hour TTL - Lifecycle hooks for connection management (onModuleInit/onModuleDestroy) - Automatic retry with exponential backoff on connection errors - Global module - no explicit imports needed Tests verify: - Connection initialization and health checks - FIFO enqueue/dequeue behavior - Status lifecycle transitions - Concurrent task handling - Queue management operations - Complete task processing workflows
This commit is contained in:
16
apps/api/src/valkey/valkey.module.ts
Normal file
16
apps/api/src/valkey/valkey.module.ts
Normal file
@@ -0,0 +1,16 @@
|
||||
import { Module, Global } from '@nestjs/common';
|
||||
import { ValkeyService } from './valkey.service';
|
||||
|
||||
/**
|
||||
* ValkeyModule - Redis-compatible task queue module
|
||||
*
|
||||
* This module provides task queue functionality using Valkey (Redis-compatible).
|
||||
* It is marked as @Global to allow injection across the application without
|
||||
* explicit imports.
|
||||
*/
|
||||
@Global()
|
||||
@Module({
|
||||
providers: [ValkeyService],
|
||||
exports: [ValkeyService],
|
||||
})
|
||||
export class ValkeyModule {}
|
||||
Reference in New Issue
Block a user