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

Add sync driver for queue messages #3070

Merged
merged 3 commits into from
Dec 19, 2023
Merged

Conversation

Weiko
Copy link
Member

@Weiko Weiko commented Dec 19, 2023

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

Screenshot 2023-12-19 at 11 31 39

Copy link

github-actions bot commented Dec 19, 2023

Warnings
⚠️ Changes were made to the enviroment variables, but not to the documentation - Please review your changes and check if a change needs to be documented!

Generated by 🚫 dangerJS against 204c257

Copy link
Member

@magrinj magrinj left a 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) {
Copy link
Member

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
Copy link
Member Author

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;
Copy link
Member Author

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);
Copy link
Member Author

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

@Weiko Weiko merged commit e799c84 into main Dec 19, 2023
13 checks passed
@Weiko Weiko deleted the c--add-sync-driver-for-queue-messages branch December 19, 2023 12:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants