Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- require 'resque/failure/multiple'
- require 'resque/failure/redis'
- require 'postmark'
- require 'mail'
- module Resque
- module Failure
- class RetryNotifier < Base
- class << self
- attr_accessor :smtp, :sender, :recipients
- end
- def self.configure
- yield self
- Resque::Failure.backend = self unless Resque::Failure.backend == Resque::Failure::Multiple
- end
- def deliver_system_email
- ResqueFailureSystemNotifier.notification_email(post.author.email, exception, worker, queue, payload.inspect)
- end
- def deliver_human_readable_email
- if count == 9
- ResqueFailureNotifier.notification_email(post.author, post)
- elsif count >= (limit-1)
- ResquePermanentFailureNotifier.notification_email(post.author, post)
- end
- end
- def post
- @post ||= Post.find(payload['args'][0]) if payload['class'] == 'Post'
- end
- def count
- @count ||= Resque.redis.get(Post.redis_retry_key(payload['args'])).to_i if post
- end
- def limit
- Post.retry_limit
- end
- def deliver_message?
- post && (count == 9 || count >= (limit-1))
- end
- def save
- Grant::ThreadStatus.disable
- if deliver_message?
- deliver_system_email
- deliver_human_readable_email
- end
- rescue => err
- puts err
- end
- end
- end
- end
Add Comment
Please, Sign In to add comment