Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(cli): add disconnect event #1551

Merged
merged 1 commit into from
Jan 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions cli/src/lib/conn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ const conn = (options: ConnectOptions) => {
client.on('close', () => {
basicLog.close()
})

client.on('disconnect', () => {
basicLog.disconnect()
})
}

const benchConn = async (options: BenchConnectOptions) => {
Expand Down Expand Up @@ -119,6 +123,10 @@ const benchConn = async (options: BenchConnectOptions) => {
connectedCount > 0 && (connectedCount -= 1)
benchLog.close(connectedCount, count, opts.clientId!)
})

client.on('disconnect', () => {
basicLog.disconnect(opts.clientId!)
})
})(i, connOpts)

await delay(interval)
Expand Down
8 changes: 8 additions & 0 deletions cli/src/lib/pub.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,10 @@ const multisend = (
const { reconnectPeriod } = connOpts
reconnectPeriod ? sender.cork() : process.exit(1)
})

client.on('disconnect', () => {
basicLog.disconnect()
})
}

const pub = (options: PublishOptions) => {
Expand Down Expand Up @@ -326,6 +330,10 @@ const multiPub = async (commandType: CommandType, options: BenchPublishOptions |
connectedCount > 0 && (connectedCount -= 1)
benchLog.close(connectedCount, count, opts.clientId!)
})

client.on('disconnect', () => {
basicLog.disconnect(opts.clientId!)
})
})(i, connOpts)

await delay(interval)
Expand Down
8 changes: 8 additions & 0 deletions cli/src/lib/sub.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,10 @@ const sub = (options: SubscribeOptions) => {
client.on('close', () => {
!outputModeClean && basicLog.close()
})

client.on('disconnect', () => {
!outputModeClean && basicLog.disconnect()
})
}

const benchSub = async (options: BenchSubscribeOptions) => {
Expand Down Expand Up @@ -278,6 +282,10 @@ const benchSub = async (options: BenchSubscribeOptions) => {
connectedCount > 0 && (connectedCount -= 1)
benchLog.close(connectedCount, count, opts.clientId!)
})

client.on('disconnect', () => {
basicLog.disconnect(opts.clientId!)
})
})(i, connOpts)

await delay(interval)
Expand Down
2 changes: 2 additions & 0 deletions cli/src/utils/signale.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ const basicLog = {
close: () => signale.error('Connection closed'),
reconnecting: () => signale.await('Reconnecting...'),
reconnectTimesLimit: () => signale.error('Exceed the maximum reconnect times limit, stop retry'),
disconnect: (clientId?: string) =>
signale.warn(`${clientId ? `Client ID: ${clientId}, ` : ''}The Broker has actively disconnected`),
}

const benchLog = {
Expand Down
Loading