Class: Warren::Config::Consumers
- Inherits:
-
Object
- Object
- Warren::Config::Consumers
- Defined in:
- lib/warren/config/consumers.rb
Overview
Manages the configuration of consumers. By default, consumer configuration is held in config/warren_consumers.yml
Constant Summary collapse
- DEFAULT_PATH =
Default path to the consumer configuration file
'config/warren_consumers.yml'
- WRITE_ONLY_TRUNCATE =
'w'
Instance Method Summary collapse
-
#add_consumer(name, desc:, queue:, bindings:, subscribed_class:, delay:) ⇒ Hash
Register a new consumer.
-
#all_consumers ⇒ Array<string>
Returns a list of all registered consumers.
- #consumer(name) ⇒ Object
-
#consumer_exist?(name) ⇒ Boolean
Checks whether a consumer has already been registered.
-
#initialize(path) ⇒ Consumers
constructor
A new instance of Consumers.
-
#save ⇒ Void
Save the configuration to ‘@path`.
Constructor Details
#initialize(path) ⇒ Consumers
Returns a new instance of Consumers.
16 17 18 19 |
# File 'lib/warren/config/consumers.rb', line 16 def initialize(path) @path = path @config = load_config end |
Instance Method Details
#add_consumer(name, desc:, queue:, bindings:, subscribed_class:, delay:) ⇒ Hash
Register a new consumer
rubocop:todo Metrics/ParameterLists
68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/warren/config/consumers.rb', line 68 def add_consumer(name, desc:, queue:, bindings:, subscribed_class:, delay:) dead_letter_exchange = "#{name}.dead-letters" @config[name] = { 'desc' => desc, 'queue' => queue_config(queue, bindings, dead_letter_exchange), 'subscribed_class' => subscribed_class, # This smells wrong. I don't like the call back out to the App namespace 'dead_letters' => queue_config(dead_letter_exchange, Warren::App::ExchangeConfig.default_dead_letter(dead_letter_exchange)), 'delay' => delay_exchange_configuration(ttl: delay, original_queue: queue, consumer_name: name), 'worker_count' => 3 } end |
#all_consumers ⇒ Array<string>
Returns a list of all registered consumers
52 53 54 |
# File 'lib/warren/config/consumers.rb', line 52 def all_consumers @config.keys end |
#consumer(name) ⇒ Object
43 44 45 |
# File 'lib/warren/config/consumers.rb', line 43 def consumer(name) @config.fetch(name) { raise StandardError, "Unknown consumer '#{name}'" } end |
#consumer_exist?(name) ⇒ Boolean
Checks whether a consumer has already been registered
39 40 41 |
# File 'lib/warren/config/consumers.rb', line 39 def consumer_exist?(name) @config.key?(name) end |
#save ⇒ Void
Save the configuration to ‘@path`
26 27 28 29 30 |
# File 'lib/warren/config/consumers.rb', line 26 def save File.open(@path, WRITE_ONLY_TRUNCATE) do |file| file.write YAML.dump(@config) end end |