Class: Resque::Failure::Hoptoad
- Inherits:
-
Base
- Object
- Base
- Resque::Failure::Hoptoad
show all
- 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
Constant Summary
collapse
- INPUT_FORMAT =
%r{^([^:]+):(\d+)(?::in `([^']+)')?$}.freeze
Class Attribute Summary collapse
Attributes inherited from Base
#exception, #payload, #queue, #worker
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from Base
all, clear, #initialize, #log
Class Attribute Details
.api_key ⇒ Object
Returns the value of attribute api_key.
20
21
22
|
# File 'lib/resque/failure/hoptoad.rb', line 20
def api_key
@api_key
end
|
.secure ⇒ Object
Returns the value of attribute secure.
20
21
22
|
# File 'lib/resque/failure/hoptoad.rb', line 20
def secure
@secure
end
|
.subdomain ⇒ Object
Returns the value of attribute subdomain.
20
21
22
|
# File 'lib/resque/failure/hoptoad.rb', line 20
def subdomain
@subdomain
end
|
Class Method Details
33
34
35
36
|
# File 'lib/resque/failure/hoptoad.rb', line 33
def self.configure
yield self
Resque::Failure.backend = self
end
|
.count ⇒ Object
27
28
29
30
31
|
# File 'lib/resque/failure/hoptoad.rb', line 27
def self.count
Stat[:failed]
end
|
.url ⇒ Object
23
24
25
|
# File 'lib/resque/failure/hoptoad.rb', line 23
def self.url
"http://#{subdomain}.hoptoadapp.com/" if subdomain
end
|
Instance Method Details
#api_key ⇒ Object
117
118
119
|
# File 'lib/resque/failure/hoptoad.rb', line 117
def api_key
self.class.api_key
end
|
#fill_in_backtrace_lines(x) ⇒ Object
106
107
108
109
110
111
|
# File 'lib/resque/failure/hoptoad.rb', line 106
def fill_in_backtrace_lines(x)
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
|
# File 'lib/resque/failure/hoptoad.rb', line 40
def save
http = use_ssl? ? :https : :http
url = URI.parse("#{http}://hoptoadapp.com/notifier_api/v2/notices")
http = Net::HTTP.new(url.host, url.port)
= {
'Content-type' => 'text/xml',
'Accept' => 'text/xml, application/xml'
}
http.read_timeout = 5 http.open_timeout = 2
http.use_ssl = use_ssl?
begin
response = http.post(url.path, xml, )
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
113
114
115
|
# File 'lib/resque/failure/hoptoad.rb', line 113
def use_ssl?
self.class.secure
end
|
#xml ⇒ Object
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
|
# File 'lib/resque/failure/hoptoad.rb', line 70
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.class exception.class.name
x.message "#{exception.class.name}: #{exception.message}"
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",RAILS_ENV)
end
end
end
|