Class: Pwwka::Configuration
- Inherits:
-
Object
- Object
- Pwwka::Configuration
- Defined in:
- lib/pwwka/configuration.rb
Instance Attribute Summary collapse
- #app_id ⇒ Object
- #async_job_klass ⇒ Object
-
#background_job_processor ⇒ Object
Returns the value of attribute background_job_processor.
-
#default_prefetch ⇒ Object
Returns the value of attribute default_prefetch.
-
#delayed_exchange_name ⇒ Object
Returns the value of attribute delayed_exchange_name.
- #error_handling_chain ⇒ Object
-
#log_hooks ⇒ Object
Returns the value of attribute log_hooks.
-
#log_level ⇒ Object
Returns the value of attribute log_level.
-
#logger ⇒ Object
Returns the value of attribute logger.
-
#options ⇒ Object
Returns the value of attribute options.
-
#process_name ⇒ Object
Returns the value of attribute process_name.
-
#rabbit_mq_host ⇒ Object
Returns the value of attribute rabbit_mq_host.
-
#requeue_on_error ⇒ Object
Returns the value of attribute requeue_on_error.
-
#send_message_resque_backoff_strategy ⇒ Object
Returns the value of attribute send_message_resque_backoff_strategy.
-
#topic_exchange_name ⇒ Object
Returns the value of attribute topic_exchange_name.
Instance Method Summary collapse
- #allow_delayed? ⇒ Boolean
-
#initialize ⇒ Configuration
constructor
A new instance of Configuration.
- #keep_alive_on_handler_klass_exceptions=(val) ⇒ Object
- #keep_alive_on_handler_klass_exceptions? ⇒ Boolean
-
#omit_payload_from_log?(level_of_message_with_payload) ⇒ Boolean
True if we should omit the payload from the log.
- #payload_logging ⇒ Object
- #payload_logging=(new_payload_logging_level) ⇒ Object
-
#payload_parser ⇒ Object
Returns a proc that, when called with the payload, parses it according to the configuration.
-
#receive_raw_payload=(val) ⇒ Object
Set this if you don’t want the payload parsed.
Constructor Details
#initialize ⇒ Configuration
Returns a new instance of Configuration.
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/pwwka/configuration.rb', line 24 def initialize @rabbit_mq_host = nil @topic_exchange_name = "pwwka.topics.#{Pwwka.environment}" @delayed_exchange_name = "pwwka.delayed.#{Pwwka.environment}" @logger = MonoLogger.new(STDOUT) @log_level = :info @log_hooks = {} @options = {} @send_message_resque_backoff_strategy = [5, #intermittent glitch? 60, # quick interruption 600, 600, 600] # longer-term outage? @requeue_on_error = false @keep_alive_on_handler_klass_exceptions = false @background_job_processor = :resque @default_prefetch = nil @receive_raw_payload = false @process_name = "" end |
Instance Attribute Details
#app_id ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/pwwka/configuration.rb', line 47 def app_id if @app_id.to_s.strip == "" if defined?(Rails) if Rails.respond_to?(:application) && Rails.respond_to?(:version) app_klass = Rails.application.class app_parent = app_klass.module_parent app_parent.name else raise "'Rails' is defined, but it doesn't respond to #application or #version, so could not derive the app_id; you must explicitly set it" end else raise "Could not derive the app_id; you must explicitly set it" end else @app_id end end |
#async_job_klass ⇒ Object
65 66 67 |
# File 'lib/pwwka/configuration.rb', line 65 def async_job_klass @async_job_klass || background_jobs[background_job_processor] end |
#background_job_processor ⇒ Object
Returns the value of attribute background_job_processor.
15 16 17 |
# File 'lib/pwwka/configuration.rb', line 15 def background_job_processor @background_job_processor end |
#default_prefetch ⇒ Object
Returns the value of attribute default_prefetch.
17 18 19 |
# File 'lib/pwwka/configuration.rb', line 17 def default_prefetch @default_prefetch end |
#delayed_exchange_name ⇒ Object
Returns the value of attribute delayed_exchange_name.
10 11 12 |
# File 'lib/pwwka/configuration.rb', line 10 def delayed_exchange_name @delayed_exchange_name end |
#error_handling_chain ⇒ Object
81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/pwwka/configuration.rb', line 81 def error_handling_chain @error_handling_chain ||= begin klasses = [ Pwwka::ErrorHandlers::IgnorePayloadFormatErrors ] if self.requeue_on_error klasses << Pwwka::ErrorHandlers::NackAndRequeueOnce else klasses << Pwwka::ErrorHandlers::NackAndIgnore end unless self.keep_alive_on_handler_klass_exceptions? klasses << Pwwka::ErrorHandlers::Crash end klasses end end |
#log_hooks ⇒ Object
Returns the value of attribute log_hooks.
13 14 15 |
# File 'lib/pwwka/configuration.rb', line 13 def log_hooks @log_hooks end |
#log_level ⇒ Object
Returns the value of attribute log_level.
12 13 14 |
# File 'lib/pwwka/configuration.rb', line 12 def log_level @log_level end |
#logger ⇒ Object
Returns the value of attribute logger.
11 12 13 |
# File 'lib/pwwka/configuration.rb', line 11 def logger @logger end |
#options ⇒ Object
Returns the value of attribute options.
14 15 16 |
# File 'lib/pwwka/configuration.rb', line 14 def @options end |
#process_name ⇒ Object
Returns the value of attribute process_name.
18 19 20 |
# File 'lib/pwwka/configuration.rb', line 18 def process_name @process_name end |
#rabbit_mq_host ⇒ Object
Returns the value of attribute rabbit_mq_host.
8 9 10 |
# File 'lib/pwwka/configuration.rb', line 8 def rabbit_mq_host @rabbit_mq_host end |
#requeue_on_error ⇒ Object
Returns the value of attribute requeue_on_error.
19 20 21 |
# File 'lib/pwwka/configuration.rb', line 19 def requeue_on_error @requeue_on_error end |
#send_message_resque_backoff_strategy ⇒ Object
Returns the value of attribute send_message_resque_backoff_strategy.
16 17 18 |
# File 'lib/pwwka/configuration.rb', line 16 def @send_message_resque_backoff_strategy end |
#topic_exchange_name ⇒ Object
Returns the value of attribute topic_exchange_name.
9 10 11 |
# File 'lib/pwwka/configuration.rb', line 9 def topic_exchange_name @topic_exchange_name end |
Instance Method Details
#allow_delayed? ⇒ Boolean
77 78 79 |
# File 'lib/pwwka/configuration.rb', line 77 def allow_delayed? [:allow_delayed] end |
#keep_alive_on_handler_klass_exceptions=(val) ⇒ Object
96 97 98 99 100 101 102 103 |
# File 'lib/pwwka/configuration.rb', line 96 def keep_alive_on_handler_klass_exceptions=(val) @keep_alive_on_handler_klass_exceptions = val if @keep_alive_on_handler_klass_exceptions @error_handling_chain.delete(Pwwka::ErrorHandlers::Crash) elsif !@error_handling_chain.include?(Pwwka::ErrorHandlers::Crash) @error_handling_chain << Pwwka::ErrorHandlers::Crash end end |
#keep_alive_on_handler_klass_exceptions? ⇒ Boolean
43 44 45 |
# File 'lib/pwwka/configuration.rb', line 43 def keep_alive_on_handler_klass_exceptions? @keep_alive_on_handler_klass_exceptions end |
#omit_payload_from_log?(level_of_message_with_payload) ⇒ Boolean
True if we should omit the payload from the log
::level_of_message_with_payload the level of the message about to be logged
148 149 150 151 |
# File 'lib/pwwka/configuration.rb', line 148 def omit_payload_from_log?() return true if @receive_raw_payload Pwwka::Logging::LEVELS[Pwwka.configuration.payload_logging.to_sym] > Pwwka::Logging::LEVELS[.to_sym] end |
#payload_logging ⇒ Object
69 70 71 |
# File 'lib/pwwka/configuration.rb', line 69 def payload_logging @payload_logging || :info end |
#payload_logging=(new_payload_logging_level) ⇒ Object
73 74 75 |
# File 'lib/pwwka/configuration.rb', line 73 def payload_logging=(new_payload_logging_level) @payload_logging = new_payload_logging_level end |
#payload_parser ⇒ Object
Returns a proc that, when called with the payload, parses it according to the configuration.
By default, this will assume the payload is JSON, parse it, and return a HashWithIndifferentAccess.
135 136 137 138 139 140 141 142 143 |
# File 'lib/pwwka/configuration.rb', line 135 def payload_parser @payload_parser ||= if @receive_raw_payload ->(payload) { payload } else ->(payload) { ActiveSupport::HashWithIndifferentAccess.new(JSON.parse(payload)) } end end |
#receive_raw_payload=(val) ⇒ Object
Set this if you don’t want the payload parsed. This can be useful is you are expecting a lot of malformed JSON or if you aren’t using JSON at all. Note that currently, setting this to true will prevent all payloads from being logged
127 128 129 130 |
# File 'lib/pwwka/configuration.rb', line 127 def receive_raw_payload=(val) @receive_raw_payload = val @payload_parser = nil end |