Module: Phobos
- Defined in:
- lib/phobos/deep_struct.rb,
lib/phobos.rb,
lib/phobos/cli.rb,
lib/phobos/log.rb,
lib/phobos/errors.rb,
lib/phobos/handler.rb,
lib/phobos/version.rb,
lib/phobos/executor.rb,
lib/phobos/listener.rb,
lib/phobos/producer.rb,
lib/phobos/cli/start.rb,
lib/phobos/constants.rb,
lib/phobos/processor.rb,
lib/phobos/cli/runner.rb,
lib/phobos/test/helper.rb,
lib/phobos/echo_handler.rb,
lib/phobos/batch_handler.rb,
lib/phobos/batch_message.rb,
lib/phobos/instrumentation.rb,
lib/phobos/actions/process_batch.rb,
lib/phobos/actions/process_message.rb,
lib/phobos/actions/process_batch_inline.rb
Overview
Please use this with at least the same consideration as you would when using OpenStruct. Right now we only use this to parse our internal configuration files. It is not meant to be used on incoming data.
Defined Under Namespace
Modules: Actions, BatchHandler, CLI, Constants, Handler, Instrumentation, Log, LoggerHelper, Processor, Producer, Test Classes: AbortError, BatchMessage, DeepStruct, EchoHandler, Error, Executor, Listener
Constant Summary collapse
- VERSION =
'2.1.0'
Class Attribute Summary collapse
-
.config ⇒ Object
readonly
Returns the value of attribute config.
-
.logger ⇒ Object
readonly
Returns the value of attribute logger.
-
.silence_log ⇒ Object
Returns the value of attribute silence_log.
Class Method Summary collapse
- .add_listeners(configuration) ⇒ Object
- .configure(configuration) ⇒ Object
-
.configure_logger ⇒ Object
:nodoc:.
- .create_exponential_backoff(backoff_config = nil) ⇒ Object
- .create_kafka_client(config_key = nil) ⇒ Object
- .deprecate(message) ⇒ Object
Class Attribute Details
.config ⇒ Object (readonly)
Returns the value of attribute config.
53 54 55 |
# File 'lib/phobos.rb', line 53 def config @config end |
.logger ⇒ Object (readonly)
Returns the value of attribute logger.
53 54 55 |
# File 'lib/phobos.rb', line 53 def logger @logger end |
.silence_log ⇒ Object
Returns the value of attribute silence_log.
54 55 56 |
# File 'lib/phobos.rb', line 54 def silence_log @silence_log end |
Class Method Details
.add_listeners(configuration) ⇒ Object
68 69 70 71 |
# File 'lib/phobos.rb', line 68 def add_listeners(configuration) listeners_config = fetch_configuration(configuration) @config.listeners += listeners_config.listeners end |
.configure(configuration) ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/phobos.rb', line 56 def configure(configuration) @config = fetch_configuration(configuration) @config.class.send(:define_method, :producer_hash) do Phobos.config.producer&.to_hash&.except(:kafka) end @config.class.send(:define_method, :consumer_hash) do Phobos.config.consumer&.to_hash&.except(:kafka) end @config.listeners ||= [] configure_logger end |
.configure_logger ⇒ Object
:nodoc:
96 97 98 99 100 101 102 103 104 105 106 |
# File 'lib/phobos.rb', line 96 def configure_logger Logging.backtrace(true) Logging.logger.root.level = silence_log ? :fatal : config.logger.level configure_ruby_kafka_logger configure_phobos_logger logger.info do Hash(message: 'Phobos configured', env: ENV['RAILS_ENV'] || ENV['RACK_ENV'] || 'N/A') end end |
.create_exponential_backoff(backoff_config = nil) ⇒ Object
83 84 85 86 87 88 |
# File 'lib/phobos.rb', line 83 def create_exponential_backoff(backoff_config = nil) backoff_config ||= Phobos.config.backoff.to_hash min = backoff_config[:min_ms] / 1000.0 max = backoff_config[:max_ms] / 1000.0 ExponentialBackoff.new(min, max).tap { |backoff| backoff.randomize_factor = rand } end |
.create_kafka_client(config_key = nil) ⇒ Object
73 74 75 76 77 78 79 80 81 |
# File 'lib/phobos.rb', line 73 def create_kafka_client(config_key = nil) kafka_config = config.kafka.to_hash.merge(logger: @ruby_kafka_logger) if config_key kafka_config = kafka_config.merge(**config.send(config_key)&.kafka&.to_hash || {}) end Kafka.new(**kafka_config) end |
.deprecate(message) ⇒ Object
90 91 92 93 |
# File 'lib/phobos.rb', line 90 def deprecate() location = caller.find { |line| line !~ %r{/phobos/} } warn "DEPRECATION WARNING: #{}: #{location}" end |