Module: Phobos
- Defined in:
- lib/phobos.rb,
lib/phobos/cli.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/cli/runner.rb,
lib/phobos/echo_handler.rb,
lib/phobos/instrumentation.rb
Defined Under Namespace
Modules: CLI, Handler, Instrumentation, Producer Classes: AbortError, EchoHandler, Error, Executor, Listener
Constant Summary collapse
- VERSION =
"1.0.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
- .configure(yml_path) ⇒ Object
- .configure_logger ⇒ Object
- .create_exponential_backoff ⇒ Object
- .create_kafka_client ⇒ Object
Class Attribute Details
.config ⇒ Object (readonly)
Returns the value of attribute config.
26 27 28 |
# File 'lib/phobos.rb', line 26 def config @config end |
.logger ⇒ Object (readonly)
Returns the value of attribute logger.
26 27 28 |
# File 'lib/phobos.rb', line 26 def logger @logger end |
.silence_log ⇒ Object
Returns the value of attribute silence_log.
27 28 29 |
# File 'lib/phobos.rb', line 27 def silence_log @silence_log end |
Class Method Details
.configure(yml_path) ⇒ Object
29 30 31 32 33 34 35 36 |
# File 'lib/phobos.rb', line 29 def configure(yml_path) ENV['RAILS_ENV'] = ENV['RACK_ENV'] ||= 'development' @config = Hashie::Mash.new(YAML.load_file(File.(yml_path))) @config.class.send(:define_method, :producer_hash) { Phobos.config.producer&.to_hash&.symbolize_keys } @config.class.send(:define_method, :consumer_hash) { Phobos.config.consumer&.to_hash&.symbolize_keys } configure_logger logger.info { Hash(message: 'Phobos configured', env: ENV['RACK_ENV']) } end |
.configure_logger ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/phobos.rb', line 48 def configure_logger date_pattern = '%Y-%m-%dT%H:%M:%S:%L%zZ' FileUtils.mkdir_p(File.dirname(config.logger.file)) Logging.backtrace true Logging.logger.root.level = silence_log ? :fatal : config.logger.level @logger = Logging.logger[self] @logger.appenders = [ Logging.appenders.stdout(layout: Logging.layouts.pattern(date_pattern: date_pattern)), Logging.appenders.file(config.logger.file, layout: Logging.layouts.json(date_pattern: date_pattern)) ] end |
.create_exponential_backoff ⇒ Object
42 43 44 45 46 |
# File 'lib/phobos.rb', line 42 def create_exponential_backoff min = Phobos.config.backoff.min_ms / 1000.0 max = Phobos.config.backoff.max_ms / 1000.0 ExponentialBackoff.new(min, max).tap { |backoff| backoff.randomize_factor = rand } end |
.create_kafka_client ⇒ Object
38 39 40 |
# File 'lib/phobos.rb', line 38 def create_kafka_client Kafka.new(config.kafka.to_hash.symbolize_keys) end |