-
-
Notifications
You must be signed in to change notification settings - Fork 187
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
Log reconnects #244
Log reconnects #244
Conversation
It's related/similar. This PR is good though, let's finish it! I'd like to change Optional, if possible, when the bot goes offline let's log its uptime using this info. Do note that |
To clarify, |
Ideally you want the time difference between confirmation (callback) of connect and disconnect. Also, make sure to read https://blog.dnsimple.com/2018/03/elapsed-time-with-ruby-the-right-way/ :) |
I realise I read your comment wrongly. Struggling to find out the time of disconnect - is there an event I can listen to (is goodbye the one to look for)? As far as I understood all the detection of a disconnect is in the Client library. Unless an approximation is fine (i.e. |
I think approximation is fine, but maybe later feel free to raise an event from the client library if it's not already there when the bot detects a disconnect. It would be good to "know" how long it took to reconnect, plus it can be hours, where we'll be reporting wrong "uptime". So I guess we shouldn't call it uptime, but just time since last successful connection. |
Do you think "Successfully ... after #{connected_at - self.connected_at}s" would be a bit confusing, since it's not clear that the time is from last connection till this reconnection? (I would have interpreted it as the time from initiating the current connection to the confirmation of that connection) |
lib/slack-ruby-bot/hooks/hello.rb
Outdated
log = ["Successfully #{@connected_at ? 'reconnected' : 'connected'} team #{client.team.name} (#{client.team.id}) to https://#{client.team.domain}.slack.com"] | ||
|
||
connected_at = Process.clock_gettime(Process::CLOCK_MONOTONIC) | ||
log << "after #{connected_at - self.connected_at} seconds" if self.connected_at |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should I round
this to, say, 6 decimal places?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would round it up to 1 or 2 decimals and just stick an s
at the end of it to keep it short.
lib/slack-ruby-bot/hooks/hello.rb
Outdated
|
||
def initialize(logger) | ||
self.logger = logger | ||
end | ||
|
||
def call(client, _data) | ||
return unless client && client.team | ||
logger.info "Successfully connected team #{client.team.name} (#{client.team.id}) to https://#{client.team.domain}.slack.com." | ||
log = ["Successfully #{@connected_at ? 'reconnected' : 'connected'} team #{client.team.name} (#{client.team.id}) to https://#{client.team.domain}.slack.com"] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here's a neat trick I use for this:
log = [
"Successfull ... ",
connected_at ? ... : nil,
...
].compact.join(" ")
Maybe nicer?
Merged, thank you. |
Attempt to fix #213