-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Add sync driver for queue messages #3070
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM ! Minor comment
@@ -38,15 +43,19 @@ export class MessageQueueModule { | |||
return boss; | |||
} | |||
|
|||
return new BullMQDriver(config.options); | |||
if (config.type === MessageQueueDriverType.BullMQ) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Weiko Maybe a switch...case
is more readable here
@@ -148,7 +148,7 @@ export class EnvironmentService { | |||
getMessageQueueDriverType(): MessageQueueDriverType { | |||
return ( | |||
this.configService.get<MessageQueueDriverType>('MESSAGE_QUEUE_TYPE') ?? | |||
MessageQueueDriverType.PgBoss | |||
MessageQueueDriverType.Sync |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We now use sync by default
return await job.handle(data); | ||
} | ||
work<T>(queueName: MessageQueue, handler: ({ data, id }: { data: T; id: string; }) => void | Promise<void>) { | ||
return; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nothing to do here, no worker to expect.
const jobClassName = getJobClassName(jobName); | ||
const job: MessageQueueJob<MessageQueueJobData> = this.jobsModuleRef.get(jobClassName, { strict: true }); | ||
|
||
return await job.handle(data); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We directly execute the function in sync mode
Context
We've recently added a worker for our queues however the worker needs to be running in a separated app to execute jobs. To improve the dev experience and because workers are not always meaningful for local development, this PR adds a sync driver which means jobs will be executed directly without going through a queue.
Test