Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(@nestjs/bull): Allow overriding the onApplicationShutdown behaviour #2070

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 3 additions & 1 deletion packages/bull/lib/bull.providers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@ function buildQueue(options: BullModuleOptions): Queue {
(queue as unknown as OnApplicationShutdown).onApplicationShutdown = function (
this: Queue,
) {
return this.close();
return options.onApplicationShutdown
? options.onApplicationShutdown(this)
: this.close();
};
return queue;
}
Expand Down
12 changes: 12 additions & 0 deletions packages/bull/lib/interfaces/bull-module-options.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@ export interface BullModuleOptions extends BullRootModuleOptions {
* Additional queue processors
*/
processors?: BullQueueProcessor[];

/**
* Callback for application shutdown, for eg. to do `queue.pause(true)` to pause processing
* The default behavior is `queue.close()`
*/
onApplicationShutdown?: (queue: Bull.Queue) => Promise<void>;
}

export interface BullOptionsFactory {
Expand All @@ -48,6 +54,12 @@ export interface BullModuleAsyncOptions
*/
configKey?: string;

/**
* Callback for application shutdown, for eg. to do `queue.pause(true)` to pause processing
* The default behavior is `queue.close()`
*/
onApplicationShutdown?: (queue: Bull.Queue) => Promise<void>;

/**
* Existing Provider to be used.
*/
Expand Down