Class: Toro::Listener
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ Listener
constructor
A new instance of Listener.
- #start ⇒ Object
- #stop ⇒ Object
Methods included from Actor
Constructor Details
#initialize(options = {}) ⇒ Listener
Returns a new instance of Listener.
5 6 7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/toro/listener.rb', line 5 def initialize(={}) defaults = { queues: [Toro.[:default_queue]] } .reverse_merge!(defaults) @queues = [:queues] @fetcher = [:fetcher] @manager = [:manager] @is_done = false raise 'No fetcher provided' if @fetcher.blank? raise 'No manager provided' if @manager.blank? @manager.register_actor(:listener, self) end |
Instance Method Details
#start ⇒ Object
19 20 21 22 23 24 |
# File 'lib/toro/listener.rb', line 19 def start Toro::Database.with_connection do Toro::Database.raw_connection.async_exec(channels.map { |channel| "LISTEN #{channel}" }.join('; ')) wait_for_notify end end |
#stop ⇒ Object
26 27 28 29 |
# File 'lib/toro/listener.rb', line 26 def stop Toro::Database.raw_connection.async_exec(channels.map { |channel| "UNLISTEN #{channel}" }.join('; ')) @is_done = true end |