Class: DCA::Redis::Notifier

Inherits:
Object
  • Object
show all
Defined in:
lib/dca/notifier/redis/notifier.rb

Direct Known Subclasses

DCA::RedisNotifier

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ Notifier

Returns a new instance of Notifier.



4
5
6
# File 'lib/dca/notifier/redis/notifier.rb', line 4

def initialize config
  Ohm.connect :url => "redis://#{config[:host]}:#{config[:port]}"
end

Instance Method Details

#push(object, event, options = {}) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/dca/notifier/redis/notifier.rb', line 8

def push(object, event, options = {})
  session = Session.find(:uid => object.session, :project => DCA.project_name, :area => object.class.queue).first
  unless session.present?
    session = Session.create :uid => object.session, :created => Time.now, :project => DCA.project_name,
                             :area => object.class.queue
  end

  if event == :analyze
    session.inc_analyze options[:state]
  elsif event == :fetch
    session.inc_fetch options[:state], options[:result] ? :success : :failure
  elsif event == :failure
    session.add_failure options[:exception]
  end
end