-
Notifications
You must be signed in to change notification settings - Fork 568
/
configuration.ts
47 lines (42 loc) 路 1.11 KB
/
configuration.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import {
Configuration,
HealthResult,
ILifeCycle,
IMidwayContainer,
} from '@midwayjs/core';
import { RedisServiceFactory } from './manager';
@Configuration({
namespace: 'redis',
importConfigs: [
{
default: {
redis: {},
},
},
],
})
export class RedisConfiguration implements ILifeCycle {
async onReady(container: IMidwayContainer) {
await container.getAsync(RedisServiceFactory);
}
async onStop(container: IMidwayContainer): Promise<void> {
const factory = await container.getAsync(RedisServiceFactory);
await factory.stop();
}
async onHealthCheck(container: IMidwayContainer): Promise<HealthResult> {
const factory = await container.getAsync(RedisServiceFactory);
const clients = factory.getClients();
// find status not ready
let clientName: any;
for (const [name, instance] of clients) {
if (instance.status !== 'ready' && !factory.isLowPriority(name)) {
clientName = name;
break;
}
}
return {
status: !clientName,
reason: clientName ? `redis client "${clientName}" is not ready` : '',
};
}
}