Class: Resque::Failure::Hoptoad
- Defined in:
- lib/resque/failure/hoptoad.rb
Overview
A Failure backend that sends exceptions raised by jobs to Hoptoad.
To use it, put this code in an initializer, Rake task, or wherever:
require 'resque/failure/hoptoad'
Resque::Failure::Hoptoad.configure do |config|
config.api_key = 'blah'
config.secure = true
# optional proxy support
config.proxy_host = 'x.y.z.t'
config.proxy_port = 8080
# server env support, defaults to RAILS_ENV or RACK_ENV
config.server_environment = "test"
end
Constant Summary collapse
- INPUT_FORMAT =
From the hoptoad plugin
/^([^:]+):(\d+)(?::in `([^']+)')?$/
Class Attribute Summary collapse
-
.api_key ⇒ Object
Returns the value of attribute api_key.
-
.host ⇒ Object
Returns the value of attribute host.
-
.http_open_timeout ⇒ Object
Returns the value of attribute http_open_timeout.
-
.http_read_timeout ⇒ Object
Returns the value of attribute http_read_timeout.
-
.port ⇒ Object
Returns the value of attribute port.
-
.proxy_host ⇒ Object
Returns the value of attribute proxy_host.
-
.proxy_pass ⇒ Object
Returns the value of attribute proxy_pass.
-
.proxy_port ⇒ Object
Returns the value of attribute proxy_port.
-
.proxy_user ⇒ Object
Returns the value of attribute proxy_user.
-
.secure ⇒ Object
Returns the value of attribute secure.
-
.server_environment ⇒ Object
Returns the value of attribute server_environment.
Attributes inherited from Base
#exception, #payload, #queue, #worker
Class Method Summary collapse
Instance Method Summary collapse
- #api_key ⇒ Object
- #fill_in_backtrace_lines(x) ⇒ Object
- #save ⇒ Object
- #server_environment ⇒ Object
- #use_ssl? ⇒ Boolean
- #xml ⇒ Object
Methods inherited from Base
all, clear, #initialize, #log, remove, requeue, search_count, search_results, url
Constructor Details
This class inherits a constructor from Resque::Failure::Base
Class Attribute Details
.api_key ⇒ Object
Returns the value of attribute api_key.
29 30 31 |
# File 'lib/resque/failure/hoptoad.rb', line 29 def api_key @api_key end |
.host ⇒ Object
Returns the value of attribute host.
32 33 34 |
# File 'lib/resque/failure/hoptoad.rb', line 32 def host @host end |
.http_open_timeout ⇒ Object
Returns the value of attribute http_open_timeout.
33 34 35 |
# File 'lib/resque/failure/hoptoad.rb', line 33 def http_open_timeout @http_open_timeout end |
.http_read_timeout ⇒ Object
Returns the value of attribute http_read_timeout.
33 34 35 |
# File 'lib/resque/failure/hoptoad.rb', line 33 def http_read_timeout @http_read_timeout end |
.port ⇒ Object
Returns the value of attribute port.
32 33 34 |
# File 'lib/resque/failure/hoptoad.rb', line 32 def port @port end |
.proxy_host ⇒ Object
Returns the value of attribute proxy_host.
30 31 32 |
# File 'lib/resque/failure/hoptoad.rb', line 30 def proxy_host @proxy_host end |
.proxy_pass ⇒ Object
Returns the value of attribute proxy_pass.
30 31 32 |
# File 'lib/resque/failure/hoptoad.rb', line 30 def proxy_pass @proxy_pass end |
.proxy_port ⇒ Object
Returns the value of attribute proxy_port.
30 31 32 |
# File 'lib/resque/failure/hoptoad.rb', line 30 def proxy_port @proxy_port end |
.proxy_user ⇒ Object
Returns the value of attribute proxy_user.
30 31 32 |
# File 'lib/resque/failure/hoptoad.rb', line 30 def proxy_user @proxy_user end |
.secure ⇒ Object
Returns the value of attribute secure.
29 30 31 |
# File 'lib/resque/failure/hoptoad.rb', line 29 def secure @secure end |
.server_environment ⇒ Object
Returns the value of attribute server_environment.
31 32 33 |
# File 'lib/resque/failure/hoptoad.rb', line 31 def server_environment @server_environment end |
Class Method Details
.configure {|_self| ... } ⇒ Object
42 43 44 45 |
# File 'lib/resque/failure/hoptoad.rb', line 42 def self.configure yield self Resque::Failure.backend = self end |
.count ⇒ Object
36 37 38 39 40 |
# File 'lib/resque/failure/hoptoad.rb', line 36 def self.count # We can't get the total # of errors from Hoptoad so we fake it # by asking Resque how many errors it has seen. Stat[:failed] end |
Instance Method Details
#api_key ⇒ Object
129 130 131 |
# File 'lib/resque/failure/hoptoad.rb', line 129 def api_key self.class.api_key end |
#fill_in_backtrace_lines(x) ⇒ Object
118 119 120 121 122 123 |
# File 'lib/resque/failure/hoptoad.rb', line 118 def fill_in_backtrace_lines(x) Array(exception.backtrace).each do |unparsed_line| _, file, number, method = unparsed_line.match(INPUT_FORMAT).to_a x.line :file => file,:number => number end end |
#save ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/resque/failure/hoptoad.rb', line 47 def save http = use_ssl? ? :https : :http host = self.class.host || 'hoptoadapp.com' port = self.class.port url = URI.parse("#{http}://#{host}:#{port}/notifier_api/v2/notices/") request = Net::HTTP::Proxy self.class.proxy_host, self.class.proxy_port, self.class.proxy_user, self.class.proxy_pass http = request.new(url.host, url.port) headers = { 'Content-type' => 'text/xml', 'Accept' => 'text/xml, application/xml' } http.read_timeout = self.class.http_read_timeout || 5 # seconds http.open_timeout = self.class.http_open_timeout || 2 # seconds http.use_ssl = use_ssl? begin response = http.post(url.path, xml, headers) rescue TimeoutError => e log "Timeout while contacting the Hoptoad server." end case response when Net::HTTPSuccess then log "Hoptoad Success: #{response.class}" else body = response.body if response.respond_to? :body log "Hoptoad Failure: #{response.class}\n#{body}" end end |
#server_environment ⇒ Object
133 134 135 136 |
# File 'lib/resque/failure/hoptoad.rb', line 133 def server_environment return self.class.server_environment if self.class.server_environment defined?(RAILS_ENV) ? RAILS_ENV : (ENV['RACK_ENV'] || 'development') end |
#use_ssl? ⇒ Boolean
125 126 127 |
# File 'lib/resque/failure/hoptoad.rb', line 125 def use_ssl? self.class.secure end |
#xml ⇒ Object
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 |
# File 'lib/resque/failure/hoptoad.rb', line 81 def xml x = Builder::XmlMarkup.new x.instruct! x.notice :version=>"2.0" do x.tag! "api-key", api_key x.notifier do x.name "Resqueue" x.version "0.1" x.url "http://github.com/defunkt/resque" end x.error do x.tag! "class", exception.class.name x. "#{exception.class.name}: #{exception.}" x.backtrace do fill_in_backtrace_lines(x) end end x.request do x.url queue.to_s x.component worker.to_s x.params do x.var :key=>"payload_class" do x.text! payload["class"].to_s end x.var :key=>"payload_args" do x.text! payload["args"].to_s end end end x.tag!("server-environment") do x.tag!("environment-name",server_environment) x.tag!("project-root", "RAILS_ROOT") end end end |