Module: Warren
- Defined in:
- lib/warren.rb,
lib/warren/app.rb,
lib/warren/den.rb,
lib/warren/fox.rb,
lib/warren/client.rb,
lib/warren/app/cli.rb,
lib/warren/handler.rb,
lib/warren/railtie.rb,
lib/warren/version.rb,
lib/warren/callback.rb,
lib/warren/app/config.rb,
lib/warren/exceptions.rb,
lib/warren/log_tagger.rb,
lib/warren/handler/log.rb,
lib/warren/app/consumer.rb,
lib/warren/handler/base.rb,
lib/warren/handler/test.rb,
lib/warren/message/full.rb,
lib/warren/subscription.rb,
lib/warren/message/short.rb,
lib/warren/delay_exchange.rb,
lib/warren/message/simple.rb,
lib/warren/subscriber/base.rb,
lib/warren/app/consumer_add.rb,
lib/warren/config/consumers.rb,
lib/warren/handler/broadcast.rb,
lib/warren/app/consumer_start.rb,
lib/warren/app/exchange_config.rb,
lib/warren/helpers/state_machine.rb,
lib/warren/callback/broadcast_with_warren.rb,
lib/warren/framework_adaptor/rails_adaptor.rb,
lib/warren/callback/broadcast_associated_with_warren.rb
Overview
Module Warren provides connection pooling for RabbitMQ Connections
Defined Under Namespace
Modules: App, Callback, Config, Exceptions, FrameworkAdaptor, Handler, Helpers, Message, Subscriber Classes: Client, DelayExchange, Den, Fox, LogTagger, Railtie, Subscription
Constant Summary collapse
- WARREN_TYPE =
Environmental variables
'WARREN_TYPE'
- VERSION =
Gem version number. Bump prior to release of new version
'0.4.1'
Class Method Summary collapse
-
.construct(type:, config: {}) ⇒ Warren::Handler::Base
Construct a Handler::Base of the type ‘type`.
-
.handler ⇒ Warren::Handler::Base
Returns the global Warren handler.
-
.load_configuration ⇒ Object
When we invoke the warren consumer, we end up loading warren before rails is loaded, so don’t invoke the railtie, and don’t get a change to do so until after the Rails has initialized, and thus run its ties.
-
.setup(opts, logger: Rails.logger) ⇒ Object
Constructs a Warren::Handler of the specified type and sets it as the global handler.
Class Method Details
.construct(type:, config: {}) ⇒ Warren::Handler::Base
Construct a Warren::Handler::Base of the type ‘type`. For Rails apps this is usually handled automatically by the initializer.
32 33 34 35 36 37 38 39 40 |
# File 'lib/warren.rb', line 32 def self.construct(type:, config: {}) warren_type = ENV.fetch(WARREN_TYPE, type) case warren_type when 'test' then Warren::Handler::Test.new when 'log' then Warren::Handler::Log.new(logger: config.fetch(:logger) { Rails.logger }) when 'broadcast' then Warren::Handler::Broadcast.new(**config) else raise StandardError, "Unknown type warren: #{warren_type}" end end |
.handler ⇒ Warren::Handler::Base
Returns the global Warren handler
53 54 55 |
# File 'lib/warren.rb', line 53 def self.handler @handler end |
.load_configuration ⇒ Object
When we invoke the warren consumer, we end up loading warren before rails is loaded, so don’t invoke the railtie, and don’t get a change to do so until after the Rails has initialized, and thus run its ties. I’m sure there is a proper way of handling this, but want to move on for now.
61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/warren.rb', line 61 def self.load_configuration config = begin Rails.application.config_for(:warren) rescue RuntimeError => e warn <<~WARN 🐇 WARREN CONFIGURATION ERROR #{e.} Use `warren config` to generate a basic configuration file WARN exit 1 end Warren.setup(config.deep_symbolize_keys.slice(:type, :config)) end |
.setup(opts, logger: Rails.logger) ⇒ Object
Constructs a Warren::Handler of the specified type and sets it as the global handler.
43 44 45 46 |
# File 'lib/warren.rb', line 43 def self.setup(opts, logger: Rails.logger) logger.warn 'Recreating Warren handler when one already exists' if handler.present? @handler = construct(**opts.symbolize_keys) end |