Class: DeliveryBoy::Instance
- Inherits:
-
Object
- Object
- DeliveryBoy::Instance
- Defined in:
- lib/delivery_boy/instance.rb
Overview
This class implements the actual logic of DeliveryBoy. The DeliveryBoy module has a module-level singleton instance.
Instance Method Summary collapse
- #clear_buffer ⇒ Object
- #deliver(value, topic:, **options) ⇒ Object
- #deliver_async!(value, topic:, **options) ⇒ Object
- #deliver_messages ⇒ Object
-
#initialize(config, logger) ⇒ Instance
constructor
A new instance of Instance.
- #produce(value, topic:, **options) ⇒ Object
- #shutdown ⇒ Object
Constructor Details
#initialize(config, logger) ⇒ Instance
Returns a new instance of Instance.
6 7 8 9 10 |
# File 'lib/delivery_boy/instance.rb', line 6 def initialize(config, logger) @config = config @logger = logger @async_producer = nil end |
Instance Method Details
#clear_buffer ⇒ Object
39 40 41 |
# File 'lib/delivery_boy/instance.rb', line 39 def clear_buffer sync_producer.clear_buffer end |
#deliver(value, topic:, **options) ⇒ Object
12 13 14 15 16 17 18 19 20 |
# File 'lib/delivery_boy/instance.rb', line 12 def deliver(value, topic:, **) sync_producer.produce(value, topic: topic, **) sync_producer. rescue # Make sure to clear any buffered messages if there's an error. clear_buffer raise end |
#deliver_async!(value, topic:, **options) ⇒ Object
22 23 24 |
# File 'lib/delivery_boy/instance.rb', line 22 def deliver_async!(value, topic:, **) async_producer.produce(value, topic: topic, **) end |
#deliver_messages ⇒ Object
35 36 37 |
# File 'lib/delivery_boy/instance.rb', line 35 def sync_producer. end |
#produce(value, topic:, **options) ⇒ Object
31 32 33 |
# File 'lib/delivery_boy/instance.rb', line 31 def produce(value, topic:, **) sync_producer.produce(value, topic: topic, **) end |
#shutdown ⇒ Object
26 27 28 29 |
# File 'lib/delivery_boy/instance.rb', line 26 def shutdown sync_producer.shutdown if sync_producer? async_producer.shutdown if async_producer? end |