Class: Resque::Failure::Notifier
- Inherits:
-
Base
- Object
- Base
- Resque::Failure::Notifier
show all
- Includes:
- EnvResque
- Defined in:
- lib/resque/failure/notifier.rb
Instance Method Summary
collapse
Methods included from EnvResque
#env_resque_channel, #env_resque_hook, #env_resque_host, #haz_env_resque_host?, #haz_required_envs?
Instance Method Details
#error_class ⇒ Object
60
61
62
|
# File 'lib/resque/failure/notifier.rb', line 60
def error_class
(payload && payload["class"]).to_s
end
|
#error_exception ⇒ Object
56
57
58
|
# File 'lib/resque/failure/notifier.rb', line 56
def error_exception
(exception && exception.class).to_s
end
|
#exception_logged_already? ⇒ Boolean
26
27
28
29
30
31
32
33
34
35
|
# File 'lib/resque/failure/notifier.rb', line 26
def exception_logged_already?
count = 0
failed_resque_jobs.each do |failed_job|
break if count > 1
if failed_job.include?(error_class) && failed_job.include?(error_exception)
count += 1
end
end
count > 1 ? true : false
end
|
#failed_resque_jobs ⇒ Object
37
38
39
|
# File 'lib/resque/failure/notifier.rb', line 37
def failed_resque_jobs
Resque.redis.lrange("failed", 0, 1000)
end
|
#link_to_class ⇒ Object
48
49
50
51
52
53
54
|
# File 'lib/resque/failure/notifier.rb', line 48
def link_to_class
if haz_env_resque_host?
"#{env_resque_host}/resque/failed/?class=#{error_class}"
else
error_class
end
end
|
#save ⇒ Object
12
13
14
15
16
17
18
19
20
21
22
23
24
|
# File 'lib/resque/failure/notifier.rb', line 12
def save
return unless haz_required_envs?
unless exception_logged_already?
uri = URI(env_resque_hook)
payload = {
channel: env_resque_channel,
username: "resque",
text: text,
icon_emoji: ":ghost:"
}.to_json
Net::HTTP.post_form(uri, payload: payload)
end
end
|
#text ⇒ Object
41
42
43
44
45
46
|
# File 'lib/resque/failure/notifier.rb', line 41
def text
"Worker: #{worker.to_s} \n" \
"Class: #{link_to_class} \n" \
"Exception: #{error_exception} \n" \
"Error: #{exception.to_s} \n"
end
|