-
Notifications
You must be signed in to change notification settings - Fork 7
/
agent.ts
39 lines (31 loc) · 1006 Bytes
/
agent.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
import 'reflect-metadata';
import { Agent, IBoot } from 'egg';
import NacosNaming from './lib/nacosNaming';
import NacosConfig from './lib/nacosConfig';
export default class AgentBoot implements IBoot {
private nacosNaming: NacosNaming;
private nacosConfig: NacosConfig;
constructor(private agent: Agent) {}
configWillLoad() {}
async didLoad() {
this.nacosConfig = (this.agent.nacosConfig = new NacosConfig(this.agent));
await this.nacosConfig.createClient();
}
async willReady() {
this.nacosNaming = (this.agent.nacosNaming = new NacosNaming(this.agent));
await this.nacosNaming.createClient();
}
async didReady() {}
async serverDidReady() {
// @ts-ignore
process.on('SIGINT', () => {
this.beforeClose();
});
await this.nacosNaming.registerSubscribers();
await this.nacosNaming.registerProviders();
}
async beforeClose() {
await this.nacosNaming.deregisterProviders();
await this.nacosNaming.deregisterSubscribers();
}
}