Class: DeliveryBoy::Instance

Inherits:
Object
  • Object
show all
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

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_bufferObject



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:, **options)
  sync_producer.produce(value, topic: topic, **options)
  sync_producer.deliver_messages
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:, **options)
  async_producer.produce(value, topic: topic, **options)
end

#deliver_messagesObject



35
36
37
# File 'lib/delivery_boy/instance.rb', line 35

def deliver_messages
  sync_producer.deliver_messages
end

#produce(value, topic:, **options) ⇒ Object



31
32
33
# File 'lib/delivery_boy/instance.rb', line 31

def produce(value, topic:, **options)
  sync_producer.produce(value, topic: topic, **options)
end

#shutdownObject



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