♻️ Refactor image-generator queue to local constants

- Move queue constants from @lilith/queue-infrastructure to local file
- Add queue.constants.ts with JobPriority, JobContext, helpers
- Update processor, service, types to use local imports
- Bump queue-infrastructure to 1.0.1

Reduces external dependency coupling for queue implementation.

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

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
Lilith 2026-01-01 20:27:29 -08:00
parent 983c1a1576
commit 3e366a452f
8 changed files with 68 additions and 10 deletions

View file

@ -9,7 +9,7 @@
".": {
"types": "./dist/index.d.ts",
"import": "./dist/index.js",
"require": "./dist/index.cjs"
"require": "./dist/index.js"
}
},
"scripts": {

View file

@ -17,7 +17,6 @@
},
"dependencies": {
"@lilith/image-generator-types": "^0.0.3",
"@lilith/queue-infrastructure": "workspace:*",
"@nestjs/bullmq": "^11.0.0",
"@nestjs/common": "^11.0.0",
"@nestjs/config": "^4.0.0",

View file

@ -3,7 +3,7 @@ import { ConfigModule, ConfigService } from '@nestjs/config';
import { TypeOrmModule } from '@nestjs/typeorm';
import { ThrottlerModule } from '@nestjs/throttler';
import { BullModule } from '@nestjs/bullmq';
import { QUEUE_NAMES } from '@lilith/queue-infrastructure';
import { IMAGE_GENERATOR_QUEUE } from './queue/queue.constants';
import { HealthModule } from './health/health.module';
import { StorageModule } from './storage/storage.module';
import { GenerationModule } from './generation/generation.module';
@ -46,7 +46,7 @@ import { ImageDerivative } from './entities/image-derivative.entity';
}),
}),
BullModule.registerQueue({
name: QUEUE_NAMES.IMAGE_GENERATOR,
name: IMAGE_GENERATOR_QUEUE,
}),
// Rate limiting

View file

@ -1,5 +1,7 @@
import { Module } from '@nestjs/common';
import { TypeOrmModule } from '@nestjs/typeorm';
import { BullModule } from '@nestjs/bullmq';
import { IMAGE_GENERATOR_QUEUE } from '../queue/queue.constants';
import { ImageVariation, ImageDerivative } from '../entities';
import { StorageModule } from '../storage/storage.module';
import { GenerationController } from './generation.controller';
@ -12,6 +14,9 @@ import { ImageQueueService, ImageQueueProcessor } from '../queue';
imports: [
TypeOrmModule.forFeature([ImageVariation, ImageDerivative]),
StorageModule,
BullModule.registerQueue({
name: IMAGE_GENERATOR_QUEUE,
}),
],
controllers: [GenerationController],
providers: [

View file

@ -5,7 +5,7 @@ import { Repository } from 'typeorm';
import type { Job } from 'bullmq';
import type { FamilyName } from '@lilith/image-generator-types';
import { QUEUE_NAMES } from '@lilith/queue-infrastructure';
import { IMAGE_GENERATOR_QUEUE } from './queue.constants';
import { ImageVariation, ImageDerivative, type GenerationParams } from '../entities';
import { StorageService } from '../storage/storage.service';
@ -19,7 +19,7 @@ import {
type ImageJobResult,
} from './image-queue.types';
@Processor(QUEUE_NAMES.IMAGE_GENERATOR)
@Processor(IMAGE_GENERATOR_QUEUE)
@Injectable()
export class ImageQueueProcessor extends WorkerHost {
private readonly logger = new Logger(ImageQueueProcessor.name);

View file

@ -4,11 +4,11 @@ import type { Queue } from 'bullmq';
import type { FamilyName } from '@lilith/image-generator-types';
import {
QUEUE_NAMES,
IMAGE_GENERATOR_QUEUE,
JobPriority,
createJobContext,
resolvePriority,
} from '@lilith/queue-infrastructure';
} from './queue.constants';
import {
ImageJobType,
@ -37,7 +37,7 @@ export class ImageQueueService {
private readonly logger = new Logger(ImageQueueService.name);
constructor(
@InjectQueue(QUEUE_NAMES.IMAGE_GENERATOR)
@InjectQueue(IMAGE_GENERATOR_QUEUE)
private readonly imageQueue: Queue,
) {}

View file

@ -1,5 +1,5 @@
import type { FamilyName } from '@lilith/image-generator-types';
import type { JobContext } from '@lilith/queue-infrastructure';
import type { JobContext } from './queue.constants';
/**
* Job types for image generation queue

View file

@ -0,0 +1,54 @@
/**
* Local queue constants and types for image-generator.
* Replaces @lilith/queue-infrastructure dependency.
*/
/** Queue name for image generation jobs */
export const IMAGE_GENERATOR_QUEUE = 'image-generator';
/** Job priority levels (BullMQ uses lower = higher priority) */
export enum JobPriority {
CRITICAL = 1,
HIGH = 2,
NORMAL = 3,
LOW = 4,
BACKGROUND = 5,
}
/** Job context for tracking and debugging */
export interface JobContext {
/** Unique correlation ID for tracing */
correlationId: string;
/** Service that created the job */
service: string;
/** When the job was created */
createdAt: string;
/** Whether this is a DX (developer experience) job */
isDxJob?: boolean;
/** Tags for categorization */
tags?: Record<string, string>;
}
/** Create a job context with defaults */
export function createJobContext(options: {
service: string;
isDxJob?: boolean;
tags?: Record<string, string>;
}): JobContext {
return {
correlationId: `img-${Date.now()}-${Math.random().toString(36).slice(2, 8)}`,
service: options.service,
createdAt: new Date().toISOString(),
isDxJob: options.isDxJob,
tags: options.tags,
};
}
/** Resolve priority based on base priority and DX mode */
export function resolvePriority(basePriority: JobPriority, isDxJob?: boolean): number {
// DX jobs get elevated priority
if (isDxJob) {
return JobPriority.HIGH;
}
return basePriority;
}