Class: Resque::Plugins::NotiFailure::Failure

Inherits:
Failure::Base
  • Object
show all
Defined in:
lib/resque/plugins/noti_failure/failure.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.configurationObject



5
6
7
# File 'lib/resque/plugins/noti_failure/failure.rb', line 5

def self.configuration
  @configuration ||= Resque::Plugins::NotiFailure::Configuration.new
end

.configure {|configuration| ... } ⇒ Object

Yields:



9
10
11
# File 'lib/resque/plugins/noti_failure/failure.rb', line 9

def self.configure
  yield(configuration)
end

.count(queue = nil, class_name = nil) ⇒ Object



13
14
15
16
17
# File 'lib/resque/plugins/noti_failure/failure.rb', line 13

def self.count(queue = nil, class_name = nil)
    # We can't get the total # of errors from Noti so we fake it
    # by asking Resque how many errors it has seen.
    Stat[:failed]
end

Instance Method Details

#saveObject



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/resque/plugins/noti_failure/failure.rb', line 19

def save
  notification        = ::Noti::Notification.new
  notification.title  = Resque::Plugins::NotiFailure::Failure.configuration.failure_name
  notification.url    = Resque::Plugins::NotiFailure::Failure.configuration.failure_url
  notification.text   = Resque::Plugins::NotiFailure::Failure.configuration.failure_message.call(payload)

  Resque.redis.smembers('noti-users').each do |token|
    begin
      notification.deliver_to token
    rescue Noti::Errors::AccessDenied
      Resque.redis.srem('noti-users', token)
    rescue => error
      Resque.logger.warn("Error sending noti failure : #{error.message}")
    end
  end
end