Class: BackgroundBunnies::Producer

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(connection_or_group, queue_name) ⇒ Producer

Returns a new instance of Producer.



10
11
12
13
14
15
# File 'lib/background_bunnies/producer.rb', line 10

def initialize(connection_or_group, queue_name)
  @connection = BackgroundBunnies.connect connection_or_group
  @queue_name = queue_name.to_s
  @channel = @connection.create_channel
  @queue = @connection.queue(@queue_name, :durable=>true)
end

Instance Attribute Details

#channelObject (readonly)

Returns the value of attribute channel.



5
6
7
# File 'lib/background_bunnies/producer.rb', line 5

def channel
  @channel
end

#connectionObject (readonly)

Returns the value of attribute connection.



8
9
10
# File 'lib/background_bunnies/producer.rb', line 8

def connection
  @connection
end

#queueObject (readonly)

Returns the value of attribute queue.



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

def queue
  @queue
end

#queue_nameObject (readonly)

Returns the value of attribute queue_name.



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

def queue_name
  @queue_name
end

Instance Method Details

#enqueue(payload) ⇒ Object

Publishes a Job for the Worker



20
21
22
# File 'lib/background_bunnies/producer.rb', line 20

def enqueue(payload)
  @queue.publish(JSON.generate(payload), :routing_key => @queue.name)
end