Class: BackgroundBunnies::Broadcaster

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

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#connectionObject (readonly)

Returns the value of attribute connection.



6
7
8
# File 'lib/background_bunnies/broadcaster.rb', line 6

def connection
  @connection
end

#exchangeObject (readonly)

Returns the value of attribute exchange.



7
8
9
# File 'lib/background_bunnies/broadcaster.rb', line 7

def exchange
  @exchange
end

#queue_nameObject (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