Class: QueueBus::Config
- Inherits:
-
Object
- Object
- QueueBus::Config
- Defined in:
- lib/queue_bus/config.rb
Overview
This class contains all the configuration for a running queue bus application.
Defined Under Namespace
Classes: Wrap
Constant Summary collapse
- LOCAL_MODE_VAR =
:queue_bus_local_mode
Instance Attribute Summary collapse
-
#default_app_key ⇒ Object
Returns the value of attribute default_app_key.
-
#default_queue ⇒ Object
Returns the value of attribute default_queue.
-
#hostname ⇒ Object
Returns the value of attribute hostname.
-
#incoming_queue ⇒ Object
Returns the value of attribute incoming_queue.
-
#local_mode ⇒ Object
Returns the current local mode of QueueBus.
-
#logger ⇒ Object
Returns the value of attribute logger.
-
#worker_middleware_stack ⇒ Object
readonly
Returns the value of attribute worker_middleware_stack.
Instance Method Summary collapse
- #adapter ⇒ Object
- #adapter=(val) ⇒ Object
- #before_publish=(callback) ⇒ Object
- #before_publish_callback(attributes) ⇒ Object
-
#has_adapter? ⇒ Boolean
Checks whether an adapter is set and returns true if it is.
-
#initialize ⇒ Config
constructor
A new instance of Config.
- #log_application(message) ⇒ Object
- #log_worker(message) ⇒ Object
- #redis(&block) ⇒ Object
-
#with_local_mode(mode) ⇒ Object
Overrides the current local mode for the duration of a block.
Constructor Details
#initialize ⇒ Config
Returns a new instance of Config.
14 15 16 17 18 |
# File 'lib/queue_bus/config.rb', line 14 def initialize @worker_middleware_stack = QueueBus::Middleware::Stack.new @incoming_queue = 'bus_incoming' @hostname = Socket.gethostname end |
Instance Attribute Details
#default_app_key ⇒ Object
Returns the value of attribute default_app_key.
79 80 81 |
# File 'lib/queue_bus/config.rb', line 79 def default_app_key @default_app_key end |
#default_queue ⇒ Object
Returns the value of attribute default_queue.
9 10 11 |
# File 'lib/queue_bus/config.rb', line 9 def default_queue @default_queue end |
#hostname ⇒ Object
Returns the value of attribute hostname.
9 10 11 |
# File 'lib/queue_bus/config.rb', line 9 def hostname @hostname end |
#incoming_queue ⇒ Object
Returns the value of attribute incoming_queue.
9 10 11 |
# File 'lib/queue_bus/config.rb', line 9 def incoming_queue @incoming_queue end |
#local_mode ⇒ Object
Returns the current local mode of QueueBus
29 30 31 32 33 34 35 |
# File 'lib/queue_bus/config.rb', line 29 def local_mode if Thread.current.thread_variable_get(LOCAL_MODE_VAR).is_a?(Wrap) Thread.current.thread_variable_get(LOCAL_MODE_VAR).value else @local_mode end end |
#logger ⇒ Object
Returns the value of attribute logger.
9 10 11 |
# File 'lib/queue_bus/config.rb', line 9 def logger @logger end |
#worker_middleware_stack ⇒ Object (readonly)
Returns the value of attribute worker_middleware_stack.
11 12 13 |
# File 'lib/queue_bus/config.rb', line 11 def worker_middleware_stack @worker_middleware_stack end |
Instance Method Details
#adapter ⇒ Object
63 64 65 66 67 |
# File 'lib/queue_bus/config.rb', line 63 def adapter return @adapter_instance if has_adapter? raise 'no adapter has been set' end |
#adapter=(val) ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/queue_bus/config.rb', line 49 def adapter=(val) raise "Adapter already set to #{@adapter_instance.class.name}" if has_adapter? @adapter_instance = if val.is_a?(Class) val.new elsif val.is_a?(::QueueBus::Adapters::Base) val else class_name = ::QueueBus::Util.classify(val) ::QueueBus::Util.constantize("::QueueBus::Adapters::#{class_name}").new end end |
#before_publish=(callback) ⇒ Object
84 85 86 |
# File 'lib/queue_bus/config.rb', line 84 def before_publish=(callback) @before_publish_callback = callback end |
#before_publish_callback(attributes) ⇒ Object
88 89 90 |
# File 'lib/queue_bus/config.rb', line 88 def before_publish_callback(attributes) @before_publish_callback&.call(attributes) end |
#has_adapter? ⇒ Boolean
Checks whether an adapter is set and returns true if it is.
70 71 72 |
# File 'lib/queue_bus/config.rb', line 70 def has_adapter? # rubocop:disable Naming/PredicateName !@adapter_instance.nil? end |
#log_application(message) ⇒ Object
92 93 94 |
# File 'lib/queue_bus/config.rb', line 92 def log_application() logger&.info() end |
#log_worker(message) ⇒ Object
96 97 98 |
# File 'lib/queue_bus/config.rb', line 96 def log_worker() logger&.debug() end |
#redis(&block) ⇒ Object
74 75 76 77 |
# File 'lib/queue_bus/config.rb', line 74 def redis(&block) # TODO: could allow setting for non-redis adapters adapter.redis(&block) end |
#with_local_mode(mode) ⇒ Object
Overrides the current local mode for the duration of a block. This is a threadsafe implementation. After, the global setting will be resumed.
41 42 43 44 45 46 47 |
# File 'lib/queue_bus/config.rb', line 41 def with_local_mode(mode) previous = Thread.current.thread_variable_get(LOCAL_MODE_VAR) Thread.current.thread_variable_set(LOCAL_MODE_VAR, Wrap.new(mode)) yield if block_given? ensure Thread.current.thread_variable_set(LOCAL_MODE_VAR, previous) end |