Module: SmartQue
- Defined in:
- lib/smart_que.rb,
lib/smart_que/config.rb,
lib/smart_que/errors.rb,
lib/smart_que/version.rb,
lib/smart_que/consumer.rb,
lib/smart_que/publisher.rb,
lib/smart_que/publishers/base.rb
Defined Under Namespace
Modules: Publishers Classes: Config, Consumer, Publisher, QueueNotFoundError
Constant Summary collapse
- VERSION =
"0.2.3"
Class Method Summary collapse
-
.config ⇒ Object
Methods related to configurations.
- .configure {|config| ... } ⇒ Object
- .create_connection(options = {}) ⇒ Object
- .default_log_file ⇒ Object
-
.establish_connection(options = {}) ⇒ Object
Establish bunny connection.
- .fetch_parameters(parameter, options = {}) ⇒ Object
-
.log(data) ⇒ Object
Logger.
Class Method Details
.config ⇒ Object
Methods related to configurations
15 16 17 |
# File 'lib/smart_que.rb', line 15 def self.config @config ||= Config.new end |
.configure {|config| ... } ⇒ Object
19 20 21 22 |
# File 'lib/smart_que.rb', line 19 def self.configure yield(config) if block_given? config end |
.create_connection(options = {}) ⇒ Object
37 38 39 40 41 42 43 44 45 46 |
# File 'lib/smart_que.rb', line 37 def self.create_connection( = {}) conn = Bunny.new( host: config.host, port: config.port, vhost: fetch_parameters('vhost'), username: config.username, password: config.password ) conn.start end |
.default_log_file ⇒ Object
73 74 75 76 77 78 79 80 |
# File 'lib/smart_que.rb', line 73 def self.default_log_file log_file = "log/smart_que.log" dir = File.dirname(log_file) unless File.directory?(dir) FileUtils.mkdir_p(dir) end log_file end |
.establish_connection(options = {}) ⇒ Object
Establish bunny connection
25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/smart_que.rb', line 25 def self.establish_connection( = {}) unless @conn_pool @conn_pool = ConnectionPool.new do create_connection() end end @conn_pool.with do |conn| conn end end |
.fetch_parameters(parameter, options = {}) ⇒ Object
48 49 50 |
# File 'lib/smart_que.rb', line 48 def self.fetch_parameters(parameter, = {}) ([parameter] || config.send(parameter)) end |
.log(data) ⇒ Object
Logger
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/smart_que.rb', line 53 def self.log(data) env = ENV['RAILS_ENV'] || config.env proc = Proc.new do if config.logger @logger = config.logger else logfile = config.logfile || default_log_file @logger = Logger.new(logfile, 'weekly') end end return if (env == 'testing' or env == 'test') @logger ||= proc.call @logger.info(data.inspect) end |