Class: Burninator::Broadcaster

Inherits:
Object
  • Object
show all
Defined in:
lib/burninator/broadcaster.rb

Constant Summary collapse

KEY =
"sql.active_record"

Instance Method Summary collapse

Constructor Details

#initialize(redis, channel, options = {}) ⇒ Broadcaster

Returns a new instance of Broadcaster.



10
11
12
13
14
15
# File 'lib/burninator/broadcaster.rb', line 10

def initialize(redis, channel, options = {})
  @redis = redis
  @channel = channel
  @percentage = options.fetch(:percentage)
  @ignore = options.fetch(:ignore)
end

Instance Method Details

#runObject



17
18
19
20
21
22
23
24
25
26
# File 'lib/burninator/broadcaster.rb', line 17

def run
  @subscriber ||= ActiveSupport::Notifications.subscribe(KEY) do |*args|
    event = ActiveSupport::Notifications::Event.new(*args)
    sql = event.payload[:sql].squish

    if publish?(sql)
      @redis.publish(@channel, Marshal.dump(event.payload))
    end
  end
end

#stopObject



28
29
30
# File 'lib/burninator/broadcaster.rb', line 28

def stop
  ActiveSupport::Notifications.unsubscribe(@subscriber)
end