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/cli/runner.rb,
lib/phobos/test/helper.rb,
lib/phobos/echo_handler.rb,
lib/phobos/instrumentation.rb,
lib/phobos/actions/process_batch.rb,
lib/phobos/actions/process_message.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, CLI, Constants, Handler, Instrumentation, Log, LoggerHelper, Producer, Test Classes: AbortError, DeepStruct, EchoHandler, Error, Executor, Listener

Constant Summary collapse

VERSION =
'1.8.1'

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.configObject (readonly)

Returns the value of attribute config.



34
35
36
# File 'lib/phobos.rb', line 34

def config
  @config
end

.loggerObject (readonly)

Returns the value of attribute logger.



34
35
36
# File 'lib/phobos.rb', line 34

def logger
  @logger
end

.silence_logObject

Returns the value of attribute silence_log.



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

def silence_log
  @silence_log
end

Class Method Details

.add_listeners(configuration) ⇒ Object



45
46
47
48
# File 'lib/phobos.rb', line 45

def add_listeners(configuration)
  listeners_config = fetch_configuration(configuration)
  @config.listeners += listeners_config.listeners
end

.configure(configuration) ⇒ Object



37
38
39
40
41
42
43
# File 'lib/phobos.rb', line 37

def configure(configuration)
  @config = fetch_configuration(configuration)
  @config.class.send(:define_method, :producer_hash) { Phobos.config.producer&.to_hash }
  @config.class.send(:define_method, :consumer_hash) { Phobos.config.consumer&.to_hash }
  @config.listeners ||= []
  configure_logger
end

.configure_loggerObject

:nodoc:



66
67
68
69
70
71
72
73
74
75
76
# File 'lib/phobos.rb', line 66

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



54
55
56
57
58
59
# File 'lib/phobos.rb', line 54

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_clientObject



50
51
52
# File 'lib/phobos.rb', line 50

def create_kafka_client
  Kafka.new(config.kafka.to_hash.merge(logger: @ruby_kafka_logger))
end

.deprecate(message) ⇒ Object



61
62
63
# File 'lib/phobos.rb', line 61

def deprecate(message)
  warn "DEPRECATION WARNING: #{message} #{Kernel.caller.first}"
end