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.listen throws Net::ReadTimeout #2

Closed
hmage opened this issue Jul 31, 2015 · 3 comments
Closed

bot.listen throws Net::ReadTimeout #2

hmage opened this issue Jul 31, 2015 · 3 comments

Comments

@hmage
Copy link

hmage commented Jul 31, 2015

Since bot.listen uses long polling, read timeouts are to be expected when there's no activity.

In that regard, this should be hidden from the user of the library and poll request automatically restarted.

Was expecting this behaviour initially, and learned it wasn't, the hard way — bot crashed when nobody was looking at it and it stayed down for 8 hours until I woke up to see the Net::ReadTimeout got thrown from bot.listen.

To make my bot persistent, I had to update the main loop to look like this:

while true
    begin
        bot.listen do |message|
            logfrom message
            case message.text
            when /^\/pony\b/
                derpibooru_bot.pony(message)
            when /^\/(start|help)\b/
                derpibooru_bot.sendtext(message, "Hello! I'm a bot by @hmage ...")
            end
        end
    rescue Net::ReadTimeout => e
        logerror e
    end
end

If adding automatic restart is not an option, update all examples to handle Net::ReadTimeout exception, because it will happen after a while when bot is supposed to be 24/7.

@atipugin
Copy link
Owner

Thanks for the report. Yes, it definitely should be handled by the gem. I'll make changes a soon as possible.

@hmage
Copy link
Author

hmage commented Jul 31, 2015

Thank you, much appreciated.

@atipugin
Copy link
Owner

Added exception handling in 0.2.6, please update your stuff.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants