mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-07-21 12:06:35 +08:00
feat(server): job system (#10134)
This commit is contained in:
@@ -2,13 +2,18 @@ import './config';
|
||||
|
||||
import { Global, Module } from '@nestjs/common';
|
||||
|
||||
import { CacheRedis, SessionRedis, SocketIoRedis } from './instances';
|
||||
import {
|
||||
CacheRedis,
|
||||
QueueRedis,
|
||||
SessionRedis,
|
||||
SocketIoRedis,
|
||||
} from './instances';
|
||||
|
||||
@Global()
|
||||
@Module({
|
||||
providers: [CacheRedis, SessionRedis, SocketIoRedis],
|
||||
exports: [CacheRedis, SessionRedis, SocketIoRedis],
|
||||
providers: [CacheRedis, SessionRedis, SocketIoRedis, QueueRedis],
|
||||
exports: [CacheRedis, SessionRedis, SocketIoRedis, QueueRedis],
|
||||
})
|
||||
export class RedisModule {}
|
||||
|
||||
export { CacheRedis, SessionRedis, SocketIoRedis };
|
||||
export { CacheRedis, QueueRedis, SessionRedis, SocketIoRedis };
|
||||
|
||||
@@ -31,6 +31,16 @@ class Redis extends IORedis implements OnModuleInit, OnModuleDestroy {
|
||||
client.on('error', this.errorHandler);
|
||||
return client;
|
||||
}
|
||||
|
||||
assertValidDBIndex(db: number) {
|
||||
if (db && db > 15) {
|
||||
throw new Error(
|
||||
// Redis allows [0..16) by default
|
||||
// we separate the db for different usages by `this.options.db + [0..4]`
|
||||
`Invalid database index: ${db}, must be between 0 and 11`
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Injectable()
|
||||
@@ -53,3 +63,15 @@ export class SocketIoRedis extends Redis {
|
||||
super({ ...config.redis, db: (config.redis.db ?? 0) + 3 });
|
||||
}
|
||||
}
|
||||
|
||||
@Injectable()
|
||||
export class QueueRedis extends Redis {
|
||||
constructor(config: Config) {
|
||||
super({
|
||||
...config.redis,
|
||||
db: (config.redis.db ?? 0) + 4,
|
||||
// required explicitly set to `null` by bullmq
|
||||
maxRetriesPerRequest: null,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user