Sha256: 38a82dbc1970f2da6a80f78d8d22855d3fb96e279844f5bacb84c9c678c745ce
Contents?: true
Size: 1.94 KB
Versions: 2
Compression:
Stored size: 1.94 KB
Contents
require "smart_que/version" require "smart_que/config" require "smart_que/errors" require "smart_que/publisher" require "smart_que/consumer" require "bunny" require "yaml" require "json" require "logger" require 'fileutils' module SmartQue # Methods related to configurations def self.config @config ||= Config.new end def self.configure yield(config) if block_given? config end # Establish bunny connection def self.establish_connection(options = {}) unless @conn_pool @conn_pool = ConnectionPool.new do create_connection(options) end end @conn_pool.with do |conn| # Reestablish connection if closed if !conn.open? && !conn.automatically_recover? connect(conn) end # Return connection object conn end end def self.create_connection(options = {}) conn = Bunny.new( host: config.host, port: config.port, vhost: fetch_parameters('vhost'), username: config.username, password: config.password ) connect(conn) end # Start & Connect Bunny Session def self.connect(session) begin session.start rescue Bunny::TCPConnectionFailed => ex log("Connection Failed: #{ex.message}") raise ConnectionError end end def self.fetch_parameters(parameter, options = {}) (options[parameter] || config.send(parameter)) end # Logger 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 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 end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
smart-que-0.2.6 | lib/smart_que.rb |
smart-que-0.2.5 | lib/smart_que.rb |