Module: Promiscuous::Config
- Defined in:
- lib/promiscuous/config.rb
Class Method Summary collapse
- ._configure(&block) ⇒ Object
- .backend=(value) ⇒ Object
- .best_amqp_backend ⇒ Object
- .configure(&block) ⇒ Object
- .configured? ⇒ Boolean
- .hook_fork ⇒ Object
- .reset ⇒ Object
Class Method Details
._configure(&block) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/promiscuous/config.rb', line 34 def self._configure(&block) block.call(self) if block self.app ||= Rails.application.class.parent_name.underscore rescue nil if defined?(Rails) self.backend ||= best_amqp_backend self.amqp_url ||= 'amqp://guest:guest@localhost:5672' self.publisher_amqp_url ||= self.amqp_url self.subscriber_amqp_url ||= self.amqp_url self.publisher_exchange ||= Promiscuous::AMQP::LIVE_EXCHANGE self.subscriber_exchanges ||= [Promiscuous::AMQP::LIVE_EXCHANGE] self.queue_name ||= "#{self.app}.promiscuous" self. ||= {:durable => true, :arguments => {'x-ha-policy' => 'all'}} self.redis_url ||= 'redis://localhost/' self.redis_urls ||= [self.redis_url] # TODO self.redis_slave_url ||= nil self.redis_stats_url ||= self.redis_urls.first self.stats_interval ||= 0 self.socket_timeout ||= 10 self.heartbeat ||= 60 self.hash_size ||= 2**20 # one million keys ~ 200Mb. self.prefetch ||= 1000 self.recovery_timeout ||= 10 self.logger ||= defined?(Rails) ? Rails.logger : Logger.new(STDERR).tap { |l| l.level = Logger::WARN } self.subscriber_threads ||= 10 self.error_notifier ||= proc {} self.version_field ||= '_v' self.recovery_on_boot = true if self.recovery_on_boot.nil? self.on_stats ||= proc { |rate, latency| } self.max_retries ||= defined?(Rails) ? Rails.env.production? ? 10 : 0 : 10 self.generation ||= 1 self.destroy_timeout ||= 1.hour self.destroy_check_interval ||= 10.minutes end |
.backend=(value) ⇒ Object
11 12 13 14 |
# File 'lib/promiscuous/config.rb', line 11 def self.backend=(value) @@backend = value Promiscuous::AMQP.backend = value end |
.best_amqp_backend ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/promiscuous/config.rb', line 21 def self.best_amqp_backend if RUBY_PLATFORM == 'java' begin require 'hot_bunnies' :hot_bunnies rescue LoadError :bunny end else :bunny end end |
.configure(&block) ⇒ Object
68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/promiscuous/config.rb', line 68 def self.configure(&block) reconnect_if_connected do self._configure(&block) unless self.app raise "Promiscuous.configure: please give a name to your app with \"config.app = 'your_app_name'\"" end end hook_fork end |
.configured? ⇒ Boolean
112 113 114 |
# File 'lib/promiscuous/config.rb', line 112 def self.configured? self.app != nil end |
.hook_fork ⇒ Object
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 |
# File 'lib/promiscuous/config.rb', line 80 def self.hook_fork return if @fork_hooked Kernel.module_eval do alias_method :fork_without_promiscuous, :fork def fork(&block) return fork_without_promiscuous(&block) unless Promiscuous.should_be_connected? Promiscuous.disconnect pid = if block fork_without_promiscuous do Promiscuous.connect block.call end else fork_without_promiscuous end Promiscuous.connect pid rescue Exception => e puts e puts e.backtrace.join("\n") raise e end module_function :fork end @fork_hooked = true end |
.reset ⇒ Object
16 17 18 19 |
# File 'lib/promiscuous/config.rb', line 16 def self.reset Promiscuous::AMQP.backend = nil class_variables.each { |var| class_variable_set(var, nil) } end |