platform-codebase/@packages/@infrastructure/queue-infrastructure/src/queue.module.ts
Lilith 483e0afe69 ♻️ Update import paths for package restructure
Update all source files to use new package locations:
- @lilith/design-tokens imports
- @lilith/types imports
- @lilith/validation imports
- Queue infrastructure refactor
- Analytics, landing, marketplace frontend updates
- Platform admin and profile editor updates

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

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-30 21:14:35 -08:00

132 lines
3.2 KiB
TypeScript

/**
* Platform Queue Module
*
* Provides queue infrastructure for the Lilith Platform.
* Wraps @lilith/queue-nestjs with platform-specific configuration.
*
* @example
* ```typescript
* // Root module (app.module.ts)
* @Module({
* imports: [
* PlatformQueueModule.forRoot({
* redis: {
* host: process.env.REDIS_HOST || 'localhost',
* port: parseInt(process.env.REDIS_PORT || '6379'),
* },
* }),
* ],
* })
*
* // Feature module
* @Module({
* imports: [
* PlatformQueueModule.forFeature({
* name: 'email',
* owner: 'features/email',
* processor: EmailProcessor,
* }),
* ],
* })
* ```
*/
import { DynamicModule, Module, Global } from '@nestjs/common';
import { ConfigService } from '@nestjs/config';
import { QueueModule, type QueueModuleOptions, type QueueFeatureOptions } from '@lilith/queue/nestjs';
export interface PlatformQueueRootOptions {
redis?: {
host?: string;
port?: number;
password?: string;
};
enableScheduling?: boolean;
}
export interface PlatformQueueFeatureOptions {
name: string;
owner: string;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
processor: new (...args: any[]) => any;
concurrency?: number;
jobTypes?: string[];
}
@Global()
@Module({})
export class PlatformQueueModule {
/**
* Configure root queue module with Redis connection
*/
static forRoot(options: PlatformQueueRootOptions = {}): DynamicModule {
return {
module: PlatformQueueModule,
imports: [
QueueModule.forRoot({
connection: {
host: options.redis?.host || 'localhost',
port: options.redis?.port || 6379,
password: options.redis?.password,
},
enableScheduling: options.enableScheduling ?? true,
}),
],
exports: [QueueModule],
};
}
/**
* Configure root queue module with async config
*/
static forRootAsync(): DynamicModule {
return {
module: PlatformQueueModule,
imports: [
QueueModule.forRootAsync({
inject: [ConfigService],
useFactory: (config: ConfigService): QueueModuleOptions => ({
connection: {
host: config.get('REDIS_HOST', 'localhost'),
port: config.get('REDIS_PORT', 6379),
password: config.get('REDIS_PASSWORD'),
},
enableScheduling: true,
}),
}),
],
exports: [QueueModule],
};
}
/**
* Configure feature queue with processor
*/
static forFeature(options: PlatformQueueFeatureOptions): DynamicModule {
const featureOptions: QueueFeatureOptions = {
registration: {
name: options.name,
owner: options.owner,
jobTypes: options.jobTypes || ['default'],
config: {
concurrency: options.concurrency || 5,
defaultJobOptions: {
attempts: 3,
backoff: {
type: 'exponential',
delay: 1000,
},
removeOnComplete: 100,
removeOnFail: 1000,
},
},
},
processor: options.processor,
};
return {
module: PlatformQueueModule,
imports: [QueueModule.forFeature(featureOptions)],
};
}
}