Class: BackgroundBunnies::Producer
- Inherits:
-
Object
- Object
- BackgroundBunnies::Producer
- Defined in:
- lib/background_bunnies/producer.rb
Instance Attribute Summary collapse
-
#channel ⇒ Object
readonly
Returns the value of attribute channel.
-
#connection ⇒ Object
readonly
Returns the value of attribute connection.
-
#queue ⇒ Object
readonly
Returns the value of attribute queue.
-
#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) ⇒ Producer
constructor
A new instance of Producer.
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
#channel ⇒ Object (readonly)
Returns the value of attribute channel.
5 6 7 |
# File 'lib/background_bunnies/producer.rb', line 5 def channel @channel end |
#connection ⇒ Object (readonly)
Returns the value of attribute connection.
8 9 10 |
# File 'lib/background_bunnies/producer.rb', line 8 def connection @connection end |
#queue ⇒ Object (readonly)
Returns the value of attribute queue.
6 7 8 |
# File 'lib/background_bunnies/producer.rb', line 6 def queue @queue end |
#queue_name ⇒ Object (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 |