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.0"

Class Method Summary collapse

Class Method Details

.configObject

Methods related to configurations



15
16
17
# File 'lib/smart_que.rb', line 15

def self.config
  @config ||= Config.new
end

.configure {|config| ... } ⇒ Object

Yields:



19
20
21
22
# File 'lib/smart_que.rb', line 19

def self.configure
  yield(config) if block_given?
  config
end

.default_log_fileObject



59
60
61
62
63
64
65
66
# File 'lib/smart_que.rb', line 59

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_connectionObject

Establish bunny connection



25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/smart_que.rb', line 25

def self.establish_connection
  return @conn if @conn

  @conn ||= Bunny.new(
    host: config.host,
    port: config.port,
    username: config.username,
    password: config.password)

  @conn.start
  @conn
end

.log(data) ⇒ Object

Logger



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/smart_que.rb', line 39

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