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:
Resque::Failure::Hoptoad.configure do |config|
config.api_key = 'blah'
config.secure = true
config.subdomain = 'your_hoptoad_subdomain'
end
Class Attribute Summary collapse
-
.api_key ⇒ Object
Returns the value of attribute api_key.
-
.secure ⇒ Object
Returns the value of attribute secure.
-
.subdomain ⇒ Object
Returns the value of attribute subdomain.
Attributes inherited from Base
#exception, #payload, #queue, #worker
Class Method Summary collapse
Instance Method Summary collapse
Methods inherited from Base
all, clear, #initialize, #log
Constructor Details
This class inherits a constructor from Resque::Failure::Base
Class Attribute Details
.api_key ⇒ Object
Returns the value of attribute api_key.
16 17 18 |
# File 'lib/resque/failure/hoptoad.rb', line 16 def api_key @api_key end |
.secure ⇒ Object
Returns the value of attribute secure.
16 17 18 |
# File 'lib/resque/failure/hoptoad.rb', line 16 def secure @secure end |
.subdomain ⇒ Object
Returns the value of attribute subdomain.
16 17 18 |
# File 'lib/resque/failure/hoptoad.rb', line 16 def subdomain @subdomain end |
Class Method Details
.configure {|_self| ... } ⇒ Object
29 30 31 32 |
# File 'lib/resque/failure/hoptoad.rb', line 29 def self.configure yield self Resque::Failure.backend = self end |
.count ⇒ Object
23 24 25 26 27 |
# File 'lib/resque/failure/hoptoad.rb', line 23 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 |
.url ⇒ Object
19 20 21 |
# File 'lib/resque/failure/hoptoad.rb', line 19 def self.url "http://#{subdomain}.hoptoadapp.com/" if subdomain end |
Instance Method Details
#api_key ⇒ Object
83 84 85 |
# File 'lib/resque/failure/hoptoad.rb', line 83 def api_key self.class.api_key end |
#save ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/resque/failure/hoptoad.rb', line 34 def save data = { :api_key => api_key, :error_class => exception.class.name, :error_message => "#{exception.class.name}: #{exception.message}", :backtrace => exception.backtrace, :environment => {}, :session => {}, :request => { :params => payload.merge(:worker => worker.to_s, :queue => queue.to_s) } } send_to_hoptoad(:notice => data) end |
#send_to_hoptoad(data) ⇒ Object
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 |
# File 'lib/resque/failure/hoptoad.rb', line 50 def send_to_hoptoad(data) http = use_ssl? ? :https : :http url = URI.parse("#{http}://hoptoadapp.com/notices/") http = Net::HTTP.new(url.host, url.port) headers = { 'Content-type' => 'application/json', 'Accept' => 'text/xml, application/xml' } http.read_timeout = 5 # seconds http.open_timeout = 2 # seconds http.use_ssl = use_ssl? begin response = http.post(url.path, Resque.encode(data), 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 |
#use_ssl? ⇒ Boolean
79 80 81 |
# File 'lib/resque/failure/hoptoad.rb', line 79 def use_ssl? self.class.secure end |