Class: BackgroundBunnies::Broadcaster
- Inherits:
-
Object
- Object
- BackgroundBunnies::Broadcaster
- Defined in:
- lib/background_bunnies/broadcaster.rb
Instance Attribute Summary collapse
-
#connection ⇒ Object
readonly
Returns the value of attribute connection.
-
#exchange ⇒ Object
readonly
Returns the value of attribute exchange.
-
#queue_name ⇒ Object
readonly
Returns the value of attribute queue_name.
Instance Method Summary collapse
-
#enqueue(payload) ⇒ Object
Publishes a Job for the Worker.
-
#initialize(connection_or_group, queue_name) ⇒ Broadcaster
constructor
A new instance of Broadcaster.
Constructor Details
#initialize(connection_or_group, queue_name) ⇒ Broadcaster
Returns a new instance of Broadcaster.
9 10 11 12 13 14 |
# File 'lib/background_bunnies/broadcaster.rb', line 9 def initialize(connection_or_group, queue_name) @connection = BackgroundBunnies.connect connection_or_group @queue_name = queue_name.to_s @channel = @connection.create_channel @exchange = @channel.fanout(BackgroundBunnies.broadcast_exchange_name(queue_name)) end |
Instance Attribute Details
#connection ⇒ Object (readonly)
Returns the value of attribute connection.
6 7 8 |
# File 'lib/background_bunnies/broadcaster.rb', line 6 def connection @connection end |
#exchange ⇒ Object (readonly)
Returns the value of attribute exchange.
7 8 9 |
# File 'lib/background_bunnies/broadcaster.rb', line 7 def exchange @exchange end |
#queue_name ⇒ Object (readonly)
Returns the value of attribute queue_name.
5 6 7 |
# File 'lib/background_bunnies/broadcaster.rb', line 5 def queue_name @queue_name end |
Instance Method Details
#enqueue(payload) ⇒ Object
Publishes a Job for the Worker
19 20 21 |
# File 'lib/background_bunnies/broadcaster.rb', line 19 def enqueue(payload) @exchange.publish(JSON.generate(payload)) end |