papertrail / papertrail-cli

Command-line client for Papertrail hosted syslog & app log management service
http://papertrailapp.com/
MIT License
426 stars 46 forks source link

Fatal exception on 503 when attempting to hit API #49

Closed alexwilson closed 9 years ago

alexwilson commented 9 years ago

I've run into this issue a few times now, using the latest version of the gem - Below is the exception in question:

/usr/lib/ruby/1.9.1/net/http.rb:2632:in `error!': 503 "Service Unavailable" (Net::HTTPFatalError)
        from /var/lib/gems/1.9.1/gems/papertrail-0.9.12/lib/papertrail/http_client.rb:105:in `on_complete'
        from /var/lib/gems/1.9.1/gems/papertrail-0.9.12/lib/papertrail/http_client.rb:45:in `get'
        from /var/lib/gems/1.9.1/gems/papertrail-0.9.12/lib/papertrail/search_query.rb:16:in `search'
        from /var/lib/gems/1.9.1/gems/papertrail-0.9.12/lib/papertrail/cli.rb:112:in `block in run'
        from /var/lib/gems/1.9.1/gems/papertrail-0.9.12/lib/papertrail/cli.rb:111:in `loop'
        from /var/lib/gems/1.9.1/gems/papertrail-0.9.12/lib/papertrail/cli.rb:111:in `run'
        from /var/lib/gems/1.9.1/gems/papertrail-0.9.12/bin/papertrail:5:in `<top (required)>'
        from /usr/local/bin/papertrail:23:in `load'
        from /usr/local/bin/papertrail:23:in `<main>'

This should just be a matter of a try/catch block around HTTPFatalError, with a retry and retry counter (say, 3 failures in a row = halt application?). I can submit a PR for this.

troy commented 9 years ago

Good catch. If you're up for a PR with that behavior (and the last failure halting and outputting the traceback like the current behavior), that would be great.

alexwilson commented 9 years ago

Cheers, kept seeing it on a slower system which has been fairly annoying ahaha. I've just submitted that PR, it will attempt to retry all Errno exceptions 3 times, before throwing the original exception. For GET requests I've taken the liberty of throwing in a 5 second sleep, but have skipped that measure for other requests as they're generally used for more important operations in REST.