Guest User

Untitled

a guest
Jan 24th, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.10 KB | None | 0 0
  1. # this goes in lib/resque/failure/notifier.rb
  2.  
  3. require 'resque/failure/multiple'
  4. require 'resque/failure/redis'
  5. require 'postmark'
  6. require 'mail'
  7.  
  8. module Resque
  9. module Failure
  10. class Notifier < Base
  11.  
  12. class << self
  13. attr_accessor :smtp, :sender, :recipients
  14. end
  15.  
  16. def self.configure
  17. yield self
  18. Resque::Failure.backend = self unless Resque::Failure.backend == Resque::Failure::Multiple
  19. end
  20.  
  21. def save
  22. message = Mail.new
  23. # FIXME stash the api key elsewhere
  24. message.delivery_method(Mail::Postmark, :api_key => "YOUR-SUPER-SECRET-POSTMARK-KEY-HERE")
  25. message.from = self.class.sender
  26. message.to = self.class.recipients
  27. message.subject = "Resque: #{exception}"
  28. message.content_type = "text/html"
  29. # FIXME do something other than a here doc, this is ugly
  30. message.body = <<EOT
  31. Queue: #{queue}
  32. Worker: #{worker}
  33.  
  34. #{payload.inspect}
  35.  
  36. #{exception}
  37. #{exception.backtrace.join("\n")}
  38. EOT
  39. # pull the trigger
  40. message.deliver
  41. end
  42. end
  43. end
  44. end
Add Comment
Please, Sign In to add comment