mirror of
https://github.com/docmost/docmost.git
synced 2026-08-25 03:12:15 +10:00
refactor(queue): extract shared bull config and queue registrations
This commit is contained in:
@@ -1,105 +1,20 @@
|
|||||||
import { Global, Module } from '@nestjs/common';
|
import { Global, Module } from '@nestjs/common';
|
||||||
import { BullModule } from '@nestjs/bullmq';
|
import { BullModule } from '@nestjs/bullmq';
|
||||||
import { EnvironmentService } from '../environment/environment.service';
|
import { EnvironmentService } from '../environment/environment.service';
|
||||||
import { createRetryStrategy, parseRedisUrl } from '../../common/helpers';
|
|
||||||
import { QueueName } from './constants';
|
|
||||||
import { GeneralQueueProcessor } from './processors/general-queue.processor';
|
import { GeneralQueueProcessor } from './processors/general-queue.processor';
|
||||||
|
import {
|
||||||
|
bullConfigFactory,
|
||||||
|
createQueueRegistrations,
|
||||||
|
} from './queue.registrations';
|
||||||
|
|
||||||
@Global()
|
@Global()
|
||||||
@Module({
|
@Module({
|
||||||
imports: [
|
imports: [
|
||||||
BullModule.forRootAsync({
|
BullModule.forRootAsync({
|
||||||
useFactory: (environmentService: EnvironmentService) => {
|
useFactory: bullConfigFactory,
|
||||||
const redisConfig = parseRedisUrl(environmentService.getRedisUrl());
|
|
||||||
return {
|
|
||||||
connection: {
|
|
||||||
host: redisConfig.host,
|
|
||||||
port: redisConfig.port,
|
|
||||||
password: redisConfig.password,
|
|
||||||
db: redisConfig.db,
|
|
||||||
family: redisConfig.family,
|
|
||||||
retryStrategy: createRetryStrategy(),
|
|
||||||
},
|
|
||||||
defaultJobOptions: {
|
|
||||||
attempts: 3,
|
|
||||||
backoff: {
|
|
||||||
type: 'exponential',
|
|
||||||
delay: 20 * 1000,
|
|
||||||
},
|
|
||||||
removeOnComplete: {
|
|
||||||
count: 200,
|
|
||||||
},
|
|
||||||
removeOnFail: {
|
|
||||||
count: 100,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
};
|
|
||||||
},
|
|
||||||
inject: [EnvironmentService],
|
inject: [EnvironmentService],
|
||||||
}),
|
}),
|
||||||
BullModule.registerQueue({
|
...createQueueRegistrations(),
|
||||||
name: QueueName.EMAIL_QUEUE,
|
|
||||||
}),
|
|
||||||
BullModule.registerQueue({
|
|
||||||
name: QueueName.ATTACHMENT_QUEUE,
|
|
||||||
}),
|
|
||||||
BullModule.registerQueue({
|
|
||||||
name: QueueName.GENERAL_QUEUE,
|
|
||||||
}),
|
|
||||||
BullModule.registerQueue({
|
|
||||||
name: QueueName.BILLING_QUEUE,
|
|
||||||
}),
|
|
||||||
BullModule.registerQueue({
|
|
||||||
name: QueueName.FILE_TASK_QUEUE,
|
|
||||||
defaultJobOptions: {
|
|
||||||
removeOnComplete: true,
|
|
||||||
removeOnFail: true,
|
|
||||||
attempts: 1,
|
|
||||||
},
|
|
||||||
}),
|
|
||||||
BullModule.registerQueue({
|
|
||||||
name: QueueName.SEARCH_QUEUE,
|
|
||||||
defaultJobOptions: {
|
|
||||||
removeOnComplete: true,
|
|
||||||
removeOnFail: true,
|
|
||||||
attempts: 2,
|
|
||||||
},
|
|
||||||
}),
|
|
||||||
BullModule.registerQueue({
|
|
||||||
name: QueueName.AI_QUEUE,
|
|
||||||
defaultJobOptions: {
|
|
||||||
removeOnComplete: true,
|
|
||||||
removeOnFail: true,
|
|
||||||
attempts: 1,
|
|
||||||
},
|
|
||||||
}),
|
|
||||||
BullModule.registerQueue({
|
|
||||||
name: QueueName.HISTORY_QUEUE,
|
|
||||||
defaultJobOptions: {
|
|
||||||
removeOnComplete: true,
|
|
||||||
removeOnFail: true,
|
|
||||||
attempts: 2,
|
|
||||||
},
|
|
||||||
}),
|
|
||||||
BullModule.registerQueue({
|
|
||||||
name: QueueName.NOTIFICATION_QUEUE,
|
|
||||||
}),
|
|
||||||
BullModule.registerQueue({
|
|
||||||
name: QueueName.AUDIT_QUEUE,
|
|
||||||
defaultJobOptions: {
|
|
||||||
removeOnComplete: true,
|
|
||||||
removeOnFail: true,
|
|
||||||
attempts: 3,
|
|
||||||
},
|
|
||||||
}),
|
|
||||||
BullModule.registerQueue({
|
|
||||||
name: QueueName.BASE_QUEUE,
|
|
||||||
defaultJobOptions: {
|
|
||||||
attempts: 2,
|
|
||||||
removeOnComplete: { count: 200 },
|
|
||||||
removeOnFail: { count: 100 },
|
|
||||||
},
|
|
||||||
}),
|
|
||||||
],
|
],
|
||||||
exports: [BullModule],
|
exports: [BullModule],
|
||||||
providers: [GeneralQueueProcessor],
|
providers: [GeneralQueueProcessor],
|
||||||
|
|||||||
@@ -0,0 +1,97 @@
|
|||||||
|
import { BullModule } from '@nestjs/bullmq';
|
||||||
|
import { EnvironmentService } from '../environment/environment.service';
|
||||||
|
import { createRetryStrategy, parseRedisUrl } from '../../common/helpers';
|
||||||
|
import { QueueName } from './constants';
|
||||||
|
|
||||||
|
export const bullConfigFactory = (environmentService: EnvironmentService) => {
|
||||||
|
const redisConfig = parseRedisUrl(environmentService.getRedisUrl());
|
||||||
|
return {
|
||||||
|
connection: {
|
||||||
|
host: redisConfig.host,
|
||||||
|
port: redisConfig.port,
|
||||||
|
password: redisConfig.password,
|
||||||
|
db: redisConfig.db,
|
||||||
|
family: redisConfig.family,
|
||||||
|
retryStrategy: createRetryStrategy(),
|
||||||
|
},
|
||||||
|
defaultJobOptions: {
|
||||||
|
attempts: 3,
|
||||||
|
backoff: {
|
||||||
|
type: 'exponential',
|
||||||
|
delay: 20 * 1000,
|
||||||
|
},
|
||||||
|
removeOnComplete: {
|
||||||
|
count: 200,
|
||||||
|
},
|
||||||
|
removeOnFail: {
|
||||||
|
count: 100,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
export const createQueueRegistrations = () => [
|
||||||
|
BullModule.registerQueue({
|
||||||
|
name: QueueName.EMAIL_QUEUE,
|
||||||
|
}),
|
||||||
|
BullModule.registerQueue({
|
||||||
|
name: QueueName.ATTACHMENT_QUEUE,
|
||||||
|
}),
|
||||||
|
BullModule.registerQueue({
|
||||||
|
name: QueueName.GENERAL_QUEUE,
|
||||||
|
}),
|
||||||
|
BullModule.registerQueue({
|
||||||
|
name: QueueName.BILLING_QUEUE,
|
||||||
|
}),
|
||||||
|
BullModule.registerQueue({
|
||||||
|
name: QueueName.FILE_TASK_QUEUE,
|
||||||
|
defaultJobOptions: {
|
||||||
|
removeOnComplete: true,
|
||||||
|
removeOnFail: true,
|
||||||
|
attempts: 1,
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
BullModule.registerQueue({
|
||||||
|
name: QueueName.SEARCH_QUEUE,
|
||||||
|
defaultJobOptions: {
|
||||||
|
removeOnComplete: true,
|
||||||
|
removeOnFail: true,
|
||||||
|
attempts: 2,
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
BullModule.registerQueue({
|
||||||
|
name: QueueName.AI_QUEUE,
|
||||||
|
defaultJobOptions: {
|
||||||
|
removeOnComplete: true,
|
||||||
|
removeOnFail: true,
|
||||||
|
attempts: 1,
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
BullModule.registerQueue({
|
||||||
|
name: QueueName.HISTORY_QUEUE,
|
||||||
|
defaultJobOptions: {
|
||||||
|
removeOnComplete: true,
|
||||||
|
removeOnFail: true,
|
||||||
|
attempts: 2,
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
BullModule.registerQueue({
|
||||||
|
name: QueueName.NOTIFICATION_QUEUE,
|
||||||
|
}),
|
||||||
|
BullModule.registerQueue({
|
||||||
|
name: QueueName.AUDIT_QUEUE,
|
||||||
|
defaultJobOptions: {
|
||||||
|
removeOnComplete: true,
|
||||||
|
removeOnFail: true,
|
||||||
|
attempts: 3,
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
BullModule.registerQueue({
|
||||||
|
name: QueueName.BASE_QUEUE,
|
||||||
|
defaultJobOptions: {
|
||||||
|
attempts: 2,
|
||||||
|
removeOnComplete: { count: 200 },
|
||||||
|
removeOnFail: { count: 100 },
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
];
|
||||||
Reference in New Issue
Block a user