From 8ac312a5f00032e0300d7a025abf71dc2f7bf230 Mon Sep 17 00:00:00 2001 From: kastov Date: Fri, 22 Aug 2025 18:16:26 +0300 Subject: [PATCH 1/2] feat: Enhance RedisChannelConfig with BullJobOptions for job management --- src/channel/redis.channel-config.ts | 21 +++++++++++++++++++++ src/channel/redis.channel.ts | 4 ++++ 2 files changed, 25 insertions(+) diff --git a/src/channel/redis.channel-config.ts b/src/channel/redis.channel-config.ts index 7d93c7b..1c576db 100644 --- a/src/channel/redis.channel-config.ts +++ b/src/channel/redis.channel-config.ts @@ -1,4 +1,5 @@ import { ChannelConfig } from '@nestjstools/messaging'; +import { KeepJobs } from 'bullmq'; export class RedisChannelConfig extends ChannelConfig { public readonly connection: Connection; @@ -9,6 +10,7 @@ export class RedisChannelConfig extends ChannelConfig { * Read more: https://github.com/taskforcesh/bullmq/issues/1219#issuecomment-1113903785 */ public readonly keyPrefix?: string; + public readonly bullJobOptions?: BullJobOptions; constructor({ name, @@ -39,3 +41,22 @@ interface Connection { password?: string; db?: number; } + +interface BullJobOptions { + /** + * If true, removes the job when it successfully completes + * When given a number, it specifies the maximum amount of + * jobs to keep, or you can provide an object specifying max + * age and/or count to keep. It overrides whatever setting is used in the worker. + * Default behavior is to keep the job in the completed set. + */ + removeOnComplete?: number | boolean | KeepJobs; + /** + * If true, removes the job when it fails after all attempts. + * When given a number, it specifies the maximum amount of + * jobs to keep, or you can provide an object specifying max + * age and/or count to keep. It overrides whatever setting is used in the worker. + * Default behavior is to keep the job in the failed set. + */ + removeOnFail?: number | boolean | KeepJobs; +} diff --git a/src/channel/redis.channel.ts b/src/channel/redis.channel.ts index 5187edc..2dcb26f 100644 --- a/src/channel/redis.channel.ts +++ b/src/channel/redis.channel.ts @@ -11,6 +11,10 @@ export class RedisChannel extends Channel { this.queue = new Queue(config.queue, { connection: this.config.connection, prefix: config.keyPrefix, + defaultJobOptions: { + removeOnComplete: config.bullJobOptions?.removeOnComplete, + removeOnFail: config.bullJobOptions?.removeOnFail, + }, }); } } From bd4d68e1f463b97b07645a3b7e4f997ffd585de4 Mon Sep 17 00:00:00 2001 From: kastov Date: Fri, 22 Aug 2025 19:19:51 +0300 Subject: [PATCH 2/2] fix: bullJobOptions --- src/channel/redis.channel-config.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/channel/redis.channel-config.ts b/src/channel/redis.channel-config.ts index 1c576db..6f6325f 100644 --- a/src/channel/redis.channel-config.ts +++ b/src/channel/redis.channel-config.ts @@ -21,6 +21,7 @@ export class RedisChannelConfig extends ChannelConfig { middlewares, normalizer, keyPrefix, + bullJobOptions, }: RedisChannelConfig) { super( name, @@ -32,6 +33,7 @@ export class RedisChannelConfig extends ChannelConfig { this.connection = connection; this.queue = queue; this.keyPrefix = keyPrefix; + this.bullJobOptions = bullJobOptions; } }