Class: Burninator::Broadcaster
- Inherits:
-
Object
- Object
- Burninator::Broadcaster
- Defined in:
- lib/burninator/broadcaster.rb
Constant Summary collapse
- KEY =
"sql.active_record"
Instance Method Summary collapse
-
#initialize(redis, channel, options = {}) ⇒ Broadcaster
constructor
A new instance of Broadcaster.
- #run ⇒ Object
- #stop ⇒ Object
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, = {}) @redis = redis @channel = channel @percentage = .fetch(:percentage) @ignore = .fetch(:ignore) end |
Instance Method Details
#run ⇒ Object
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 |
#stop ⇒ Object
28 29 30 |
# File 'lib/burninator/broadcaster.rb', line 28 def stop ActiveSupport::Notifications.unsubscribe(@subscriber) end |