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

fix: Management of BullMQ queue prefixes #3220

Open
wants to merge 3 commits into
base: minor
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 15 additions & 9 deletions packages/job-queue-plugin/src/bullmq/bullmq-job-queue-strategy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,21 +52,26 @@ export class BullMQJobQueueStrategy implements InspectableJobQueueStrategy {
private readonly CANCEL_JOB_CHANNEL = 'cancel-job';
private readonly CANCELLED_JOB_LIST_NAME = 'vendure:cancelled-jobs';

async init(injector: Injector): Promise<void> {
private initOptions(injector: Injector): BullMQPluginOptions {
const options = injector.get<BullMQPluginOptions>(BULLMQ_PLUGIN_OPTIONS);
this.options = {
...options,
workerOptions: {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please spread the configured worker options in there with ...(options.workerOptions ?? {}) instead of assigning it the bottom.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great point, pls see updated version.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@areg-gareginyan-im the default values of removeOnComplete and removeOnFail should be kept. If you are passing workerOptions now they would be lost.

removeOnComplete: options.workerOptions?.removeOnComplete ?? {
options.workerOptions = {
...(options.workerOptions ?? {
removeOnComplete: {
age: 60 * 60 * 24 * 30,
count: 5000,
},
removeOnFail: options.workerOptions?.removeOnFail ?? {
removeOnFail: {
age: 60 * 60 * 24 * 30,
count: 5000,
},
},
};
})
}
return options
}

async init(injector: Injector): Promise<void> {
const options = this.initOptions(injector);
this.options = options;
this.connectionOptions =
options.connection ??
({
Expand Down Expand Up @@ -413,8 +418,9 @@ export class BullMQJobQueueStrategy implements InspectableJobQueueStrategy {
args: Args,
): Promise<T> {
return new Promise<T>((resolve, reject) => {
const prefix = this.options.workerOptions?.prefix ?? 'bull';
(this.redisConnection as any)[scriptDef.name](
`bull:${this.queue.name}:`,
`${prefix}:${this.queue.name}:`,
...args,
(err: any, result: any) => {
if (err) {
Expand Down
Loading