Skip to content
This repository has been archived by the owner on Apr 17, 2024. It is now read-only.

Commit

Permalink
Delay retries, improve logging
Browse files Browse the repository at this point in the history
  • Loading branch information
benpbolton committed Nov 9, 2023
1 parent ea6c36f commit 001c533
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions src/lib/msgRoomName.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,18 @@ module.exports = (msg, next, retryCount = 0) ->
})
.header('Authorization', 'Bearer ' + process.env.HUBOT_SLACK_TOKEN)
.get() (err, response, body) ->
if err || response.ok is false || !response.channel
body = JSON.parse(body) if body
if err || response.statusCode isnt 200 || !body?.channel
if retryCount < 3 # Retry up to 3 times
console.warn "Retrying to get channel info for #{msg.message.room}"
console.warn "[Attempt #{retryCount+ 1}]"
module.exports(msg, next, retryCount + 1)
console.warn "Retry [#{retryCount + 1}] to get channel info for #{msg.message.room}"
# Retry after 1 second
setTimeout (-> module.exports(msg, next, retryCount + 1)), 1000
else
console.error "Failed to get channel name after retries for #{msg.message.room}"
error = err || (body)?.error
console.error "Failed to get channel name after #{retryCount} retries for " + \
"#{msg.message.room}. Status: #{response.statusCode}, Error: #{error}"
next null # Signal failure after retries
else
next response.channel.name
next body.channel.name
else
next msg.message.room

0 comments on commit 001c533

Please sign in to comment.