Skip to content

Commit 7796d10

Browse files
authored
feat: enhance RedisChannelConfig with BullJobOptions for job management (#5)
* feat: Enhance RedisChannelConfig with BullJobOptions for job management * fix: bullJobOptions
1 parent a5ff403 commit 7796d10

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

src/channel/redis.channel-config.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { ChannelConfig } from '@nestjstools/messaging';
2+
import { KeepJobs } from 'bullmq';
23

34
export class RedisChannelConfig extends ChannelConfig {
45
public readonly connection: Connection;
@@ -9,6 +10,7 @@ export class RedisChannelConfig extends ChannelConfig {
910
* Read more: https://github.com/taskforcesh/bullmq/issues/1219#issuecomment-1113903785
1011
*/
1112
public readonly keyPrefix?: string;
13+
public readonly bullJobOptions?: BullJobOptions;
1214

1315
constructor({
1416
name,
@@ -19,6 +21,7 @@ export class RedisChannelConfig extends ChannelConfig {
1921
middlewares,
2022
normalizer,
2123
keyPrefix,
24+
bullJobOptions,
2225
}: RedisChannelConfig) {
2326
super(
2427
name,
@@ -30,6 +33,7 @@ export class RedisChannelConfig extends ChannelConfig {
3033
this.connection = connection;
3134
this.queue = queue;
3235
this.keyPrefix = keyPrefix;
36+
this.bullJobOptions = bullJobOptions;
3337
}
3438
}
3539

@@ -39,3 +43,22 @@ interface Connection {
3943
password?: string;
4044
db?: number;
4145
}
46+
47+
interface BullJobOptions {
48+
/**
49+
* If true, removes the job when it successfully completes
50+
* When given a number, it specifies the maximum amount of
51+
* jobs to keep, or you can provide an object specifying max
52+
* age and/or count to keep. It overrides whatever setting is used in the worker.
53+
* Default behavior is to keep the job in the completed set.
54+
*/
55+
removeOnComplete?: number | boolean | KeepJobs;
56+
/**
57+
* If true, removes the job when it fails after all attempts.
58+
* When given a number, it specifies the maximum amount of
59+
* jobs to keep, or you can provide an object specifying max
60+
* age and/or count to keep. It overrides whatever setting is used in the worker.
61+
* Default behavior is to keep the job in the failed set.
62+
*/
63+
removeOnFail?: number | boolean | KeepJobs;
64+
}

src/channel/redis.channel.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ export class RedisChannel extends Channel<RedisChannelConfig> {
1111
this.queue = new Queue(config.queue, {
1212
connection: this.config.connection,
1313
prefix: config.keyPrefix,
14+
defaultJobOptions: {
15+
removeOnComplete: config.bullJobOptions?.removeOnComplete,
16+
removeOnFail: config.bullJobOptions?.removeOnFail,
17+
},
1418
});
1519
}
1620
}

0 commit comments

Comments
 (0)