From aa9473f7c6a748ac51e9ea50de6db5bd2b1cd696 Mon Sep 17 00:00:00 2001 From: Misty De Meo Date: Mon, 29 Jul 2019 16:32:05 -0700 Subject: [PATCH] Bot: catch and react to disconnection event --- src/bot.coffee | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/src/bot.coffee b/src/bot.coffee index a44ba84a..8779dc0a 100644 --- a/src/bot.coffee +++ b/src/bot.coffee @@ -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 @@ -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