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

Bot: catch and react to disconnection event #572

Merged
merged 1 commit into from
Jul 30, 2019
Merged
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
21 changes: 15 additions & 6 deletions src/bot.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ class SlackBot extends Adapter
# SlackClient event handlers
@client.rtm.on "open", @open
@client.rtm.on "close", @close
@client.rtm.on "disconnect", @disconnect
@client.rtm.on "error", @error
@client.rtm.on "authenticated", @authenticated
@client.onEvent @eventHandler
Expand Down Expand Up @@ -177,16 +178,24 @@ class SlackBot extends Adapter
# @private
###
close: =>
@robot.logger.info "Disconnected from Slack RTM"
# NOTE: not confident that @options.autoReconnect works
if @options.autoReconnect
@robot.logger.info "Disconnected from Slack RTM"
@robot.logger.info "Waiting for reconnect..."
else
@robot.logger.info "Exiting..."
@client.disconnect()
# NOTE: Node recommends not to call process.exit() but Hubot itself uses this mechanism for shutting down
# Can we make sure the brain is flushed to persistence? Do we need to cleanup any state (or timestamp anything)?
process.exit 1
@disconnect()

###*
# Slack client has closed the connection and will not reconnect
# @private
###
disconnect: =>
@robot.logger.info "Disconnected from Slack RTM"
@robot.logger.info "Exiting..."
@client.disconnect()
# NOTE: Node recommends not to call process.exit() but Hubot itself uses this mechanism for shutting down
# Can we make sure the brain is flushed to persistence? Do we need to cleanup any state (or timestamp anything)?
process.exit 1

###*
# Slack client received an error
Expand Down