只有生产环境才使用服务自发现功能
This commit is contained in:
parent
b944d26044
commit
8bf7232da2
@ -5,6 +5,7 @@ const signals: NodeJS.Signals[] = ['SIGINT', 'SIGTERM', 'SIGUSR2']
|
||||
|
||||
const NODES_SET = 'poker:infosvr'
|
||||
const discovery_channel = 'poker:infosvr:discovery'
|
||||
const isProd = process.env.NODE_ENV === 'production'
|
||||
|
||||
export function registerGracefulShutdown(callback: (err?: Error) => void) {
|
||||
/**
|
||||
@ -26,6 +27,9 @@ async function getNodeAddress(port: number) {
|
||||
}
|
||||
|
||||
export async function registService(port: number) {
|
||||
if (!isProd) {
|
||||
return
|
||||
}
|
||||
const address = await getNodeAddress(port)
|
||||
const client = new RedisClient()
|
||||
await client.sadd(NODES_SET, address)
|
||||
@ -33,6 +37,9 @@ export async function registService(port: number) {
|
||||
}
|
||||
|
||||
export async function unRegistService(port: number) {
|
||||
if (!isProd) {
|
||||
return
|
||||
}
|
||||
const address = await getNodeAddress(port)
|
||||
const client = new RedisClient()
|
||||
await client.srem(NODES_SET, address)
|
||||
|
Loading…
x
Reference in New Issue
Block a user