Add pg-boss worker poc (#2991)
* Add pg-boss worker poc * add Example job * add retry limit * rename MessageQueue
This commit is contained in:
@ -2,9 +2,10 @@ import { Inject, Injectable, OnModuleDestroy } from '@nestjs/common';
|
||||
|
||||
import { QueueJobOptions } from 'src/integrations/message-queue/drivers/interfaces/job-options.interface';
|
||||
import { MessageQueueDriver } from 'src/integrations/message-queue/drivers/interfaces/message-queue-driver.interface';
|
||||
import { MessageQueueJobData } from 'src/integrations/message-queue/interfaces/message-queue-job.interface';
|
||||
|
||||
import {
|
||||
MessageQueues,
|
||||
MessageQueue,
|
||||
QUEUE_DRIVER,
|
||||
} from 'src/integrations/message-queue/message-queue.constants';
|
||||
|
||||
@ -12,7 +13,7 @@ import {
|
||||
export class MessageQueueService implements OnModuleDestroy {
|
||||
constructor(
|
||||
@Inject(QUEUE_DRIVER) protected driver: MessageQueueDriver,
|
||||
protected queueName: MessageQueues,
|
||||
protected queueName: MessageQueue,
|
||||
) {
|
||||
if (typeof this.driver.register === 'function') {
|
||||
this.driver.register(queueName);
|
||||
@ -25,11 +26,15 @@ export class MessageQueueService implements OnModuleDestroy {
|
||||
}
|
||||
}
|
||||
|
||||
add<T>(data: T, options?: QueueJobOptions): Promise<void> {
|
||||
return this.driver.add(this.queueName, data, options);
|
||||
add<T extends MessageQueueJobData>(
|
||||
jobName: string,
|
||||
data: T,
|
||||
options?: QueueJobOptions,
|
||||
): Promise<void> {
|
||||
return this.driver.add(this.queueName, jobName, data, options);
|
||||
}
|
||||
|
||||
work<T>(
|
||||
work<T extends MessageQueueJobData>(
|
||||
handler: ({ data, id }: { data: T; id: string }) => Promise<void> | void,
|
||||
) {
|
||||
return this.driver.work(this.queueName, handler);
|
||||
|
||||
Reference in New Issue
Block a user