mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-07-20 03:26:47 +08:00
refactor(server): config system (#11081)
This commit is contained in:
@@ -1,61 +1,86 @@
|
||||
import { QueueOptions, WorkerOptions } from 'bullmq';
|
||||
|
||||
import {
|
||||
defineRuntimeConfig,
|
||||
defineStartupConfig,
|
||||
ModuleConfig,
|
||||
} from '../../config';
|
||||
import { defineModuleConfig, JSONSchema } from '../../config';
|
||||
import { Queue } from './def';
|
||||
|
||||
declare module '../../config' {
|
||||
interface AppConfig {
|
||||
job: ModuleConfig<
|
||||
{
|
||||
queue: Omit<QueueOptions, 'connection'>;
|
||||
worker: Omit<WorkerOptions, 'connection'>;
|
||||
},
|
||||
{
|
||||
queues: {
|
||||
[key in Queue]: {
|
||||
concurrency: number;
|
||||
};
|
||||
};
|
||||
}
|
||||
>;
|
||||
declare global {
|
||||
interface AppConfigSchema {
|
||||
job: {
|
||||
queue: ConfigItem<Omit<QueueOptions, 'connection' | 'telemetry'>>;
|
||||
worker: ConfigItem<{
|
||||
defaultWorkerOptions: Omit<WorkerOptions, 'connection' | 'telemetry'>;
|
||||
}>;
|
||||
queues: {
|
||||
[key in Queue]: ConfigItem<{
|
||||
concurrency: number;
|
||||
}>;
|
||||
};
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
defineStartupConfig('job', {
|
||||
const schema: JSONSchema = {
|
||||
type: 'object',
|
||||
properties: {
|
||||
concurrency: { type: 'number' },
|
||||
},
|
||||
};
|
||||
|
||||
defineModuleConfig('job', {
|
||||
queue: {
|
||||
prefix: AFFiNE.node.test ? 'affine_job_test' : 'affine_job',
|
||||
defaultJobOptions: {
|
||||
attempts: 5,
|
||||
// should remove job after it's completed, because we will add a new job with the same job id
|
||||
removeOnComplete: true,
|
||||
removeOnFail: {
|
||||
age: 24 * 3600 /* 1 day */,
|
||||
count: 500,
|
||||
desc: 'The config for job queues',
|
||||
default: {
|
||||
prefix: env.testing ? 'affine_job_test' : 'affine_job',
|
||||
defaultJobOptions: {
|
||||
attempts: 5,
|
||||
// should remove job after it's completed, because we will add a new job with the same job id
|
||||
removeOnComplete: true,
|
||||
removeOnFail: {
|
||||
age: 24 * 3600 /* 1 day */,
|
||||
count: 500,
|
||||
},
|
||||
},
|
||||
},
|
||||
link: 'https://api.docs.bullmq.io/interfaces/v5.QueueOptions.html',
|
||||
},
|
||||
worker: {},
|
||||
});
|
||||
|
||||
defineRuntimeConfig('job', {
|
||||
'queues.nightly.concurrency': {
|
||||
default: 1,
|
||||
desc: 'Concurrency of worker consuming of nightly checking job queue',
|
||||
worker: {
|
||||
desc: 'The config for job workers',
|
||||
default: {
|
||||
defaultWorkerOptions: {},
|
||||
},
|
||||
link: 'https://api.docs.bullmq.io/interfaces/v5.WorkerOptions.html',
|
||||
},
|
||||
'queues.notification.concurrency': {
|
||||
default: 10,
|
||||
desc: 'Concurrency of worker consuming of notification job queue',
|
||||
|
||||
'queues.copilot': {
|
||||
desc: 'The config for copilot job queue',
|
||||
default: {
|
||||
concurrency: 1,
|
||||
},
|
||||
schema,
|
||||
},
|
||||
'queues.doc.concurrency': {
|
||||
default: 1,
|
||||
desc: 'Concurrency of worker consuming of doc job queue',
|
||||
|
||||
'queues.doc': {
|
||||
desc: 'The config for doc job queue',
|
||||
default: {
|
||||
concurrency: 1,
|
||||
},
|
||||
schema,
|
||||
},
|
||||
'queues.copilot.concurrency': {
|
||||
default: 1,
|
||||
desc: 'Concurrency of worker consuming of copilot job queue',
|
||||
|
||||
'queues.notification': {
|
||||
desc: 'The config for notification job queue',
|
||||
default: {
|
||||
concurrency: 10,
|
||||
},
|
||||
schema,
|
||||
},
|
||||
|
||||
'queues.nightly': {
|
||||
desc: 'The config for nightly job queue',
|
||||
default: {
|
||||
concurrency: 1,
|
||||
},
|
||||
schema,
|
||||
},
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user