Class: Racecar::Config
- Inherits:
-
KingKonf::Config
- Object
- KingKonf::Config
- Racecar::Config
- Defined in:
- lib/racecar/config.rb
Constant Summary collapse
- STATISTICS_DISABLED_VALUE =
0
Instance Attribute Summary collapse
-
#error_handler ⇒ Object
readonly
The error handler must be set directly on the object.
-
#logger ⇒ Object
Returns the value of attribute logger.
-
#parallel_workers ⇒ Object
Returns the value of attribute parallel_workers.
-
#subscriptions ⇒ Object
Returns the value of attribute subscriptions.
Instance Method Summary collapse
-
#initialize(env: ENV) ⇒ Config
constructor
A new instance of Config.
- #inspect ⇒ Object
- #load_consumer_class(consumer_class) ⇒ Object
- #max_wait_time_ms ⇒ Object
- #on_error(&handler) ⇒ Object
- #rdkafka_consumer ⇒ Object
- #rdkafka_producer ⇒ Object
- #statistics_interval_ms ⇒ Object
- #validate! ⇒ Object
Constructor Details
#initialize(env: ENV) ⇒ Config
Returns a new instance of Config.
184 185 186 187 188 189 |
# File 'lib/racecar/config.rb', line 184 def initialize(env: ENV) super(env: env) @error_handler = proc {} @subscriptions = [] @logger = Logger.new(STDOUT) end |
Instance Attribute Details
#error_handler ⇒ Object (readonly)
The error handler must be set directly on the object.
168 169 170 |
# File 'lib/racecar/config.rb', line 168 def error_handler @error_handler end |
#logger ⇒ Object
Returns the value of attribute logger.
170 171 172 |
# File 'lib/racecar/config.rb', line 170 def logger @logger end |
#parallel_workers ⇒ Object
Returns the value of attribute parallel_workers.
170 171 172 |
# File 'lib/racecar/config.rb', line 170 def parallel_workers @parallel_workers end |
#subscriptions ⇒ Object
Returns the value of attribute subscriptions.
170 171 172 |
# File 'lib/racecar/config.rb', line 170 def subscriptions @subscriptions end |
Instance Method Details
#inspect ⇒ Object
191 192 193 194 195 196 |
# File 'lib/racecar/config.rb', line 191 def inspect self.class.variables .map(&:name) .map {|key| [key, get(key).inspect].join(" = ") } .join("\n") end |
#load_consumer_class(consumer_class) ⇒ Object
212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 |
# File 'lib/racecar/config.rb', line 212 def load_consumer_class(consumer_class) self.group_id = consumer_class.group_id || self.group_id self.group_id ||= [ # Configurable and optional prefix: group_id_prefix, # MyFunnyConsumer => my-funny-consumer consumer_class.name.gsub(/[a-z][A-Z]/) { |str| "#{str[0]}-#{str[1]}" }.downcase, ].compact.join self.parallel_workers = consumer_class.parallel_workers self.subscriptions = consumer_class.subscriptions self.max_wait_time = consumer_class.max_wait_time || self.max_wait_time self.pidfile ||= "#{group_id}.pid" end |
#max_wait_time_ms ⇒ Object
180 181 182 |
# File 'lib/racecar/config.rb', line 180 def max_wait_time_ms max_wait_time * 1000 end |
#on_error(&handler) ⇒ Object
229 230 231 |
# File 'lib/racecar/config.rb', line 229 def on_error(&handler) @error_handler = handler end |
#rdkafka_consumer ⇒ Object
233 234 235 236 237 238 239 |
# File 'lib/racecar/config.rb', line 233 def rdkafka_consumer consumer_config = consumer.map do |param| param.split("=", 2).map(&:strip) end.to_h consumer_config.merge!(rdkafka_security_config) consumer_config end |
#rdkafka_producer ⇒ Object
241 242 243 244 245 246 247 |
# File 'lib/racecar/config.rb', line 241 def rdkafka_producer producer_config = producer.map do |param| param.split("=", 2).map(&:strip) end.to_h producer_config.merge!(rdkafka_security_config) producer_config end |
#statistics_interval_ms ⇒ Object
172 173 174 175 176 177 178 |
# File 'lib/racecar/config.rb', line 172 def statistics_interval_ms if Rdkafka::Config.statistics_callback statistics_interval * 1000 else STATISTICS_DISABLED_VALUE end end |
#validate! ⇒ Object
198 199 200 201 202 203 204 205 206 207 208 209 210 |
# File 'lib/racecar/config.rb', line 198 def validate! if brokers.empty? raise ConfigError, "`brokers` must not be empty" end if socket_timeout <= max_wait_time raise ConfigError, "`socket_timeout` must be longer than `max_wait_time`" end if max_pause_timeout && !pause_with_exponential_backoff? raise ConfigError, "`max_pause_timeout` only makes sense when `pause_with_exponential_backoff` is enabled" end end |