Guest User

Untitled

a guest
Jan 22nd, 2018
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.38 KB | None | 0 0
  1. require 'resque/failure/multiple'
  2. require 'resque/failure/redis'
  3. require 'postmark'
  4. require 'mail'
  5.  
  6. module Resque
  7. module Failure
  8. class RetryNotifier < Base
  9.  
  10. class << self
  11. attr_accessor :smtp, :sender, :recipients
  12. end
  13.  
  14. def self.configure
  15. yield self
  16. Resque::Failure.backend = self unless Resque::Failure.backend == Resque::Failure::Multiple
  17. end
  18.  
  19. def deliver_system_email
  20. ResqueFailureSystemNotifier.notification_email(post.author.email, exception, worker, queue, payload.inspect)
  21. end
  22.  
  23. def deliver_human_readable_email
  24. if count == 9
  25. ResqueFailureNotifier.notification_email(post.author, post)
  26. elsif count >= (limit-1)
  27. ResquePermanentFailureNotifier.notification_email(post.author, post)
  28. end
  29. end
  30.  
  31. def post
  32. @post ||= Post.find(payload['args'][0]) if payload['class'] == 'Post'
  33. end
  34.  
  35. def count
  36. @count ||= Resque.redis.get(Post.redis_retry_key(payload['args'])).to_i if post
  37. end
  38.  
  39. def limit
  40. Post.retry_limit
  41. end
  42.  
  43. def deliver_message?
  44. post && (count == 9 || count >= (limit-1))
  45. end
  46.  
  47. def save
  48. Grant::ThreadStatus.disable
  49.  
  50. if deliver_message?
  51. deliver_system_email
  52. deliver_human_readable_email
  53. end
  54. rescue => err
  55. puts err
  56. end
  57. end
  58. end
  59. end
Add Comment
Please, Sign In to add comment