Module: Nezu::Runtime

Defined in:
lib/nezu/runtime.rb,
lib/nezu/runtime/worker.rb,
lib/nezu/runtime/consumer.rb,
lib/nezu/runtime/producer.rb,
lib/nezu/runtime/recipient.rb

Defined Under Namespace

Modules: Common Classes: Consumer, Producer, Recipient, RecipientError, Worker

Class Method Summary collapse

Class Method Details

.configure_from_yaml(yaml_file) ⇒ Object

:nodoc:



78
79
80
81
82
83
84
85
86
# File 'lib/nezu/runtime.rb', line 78

def self.configure_from_yaml(yaml_file) #:nodoc:
  config_file = Nezu.root.join('config', yaml_file)
  if File.exist?(config_file)
    yaml = YAML.load_file(config_file)
    Nezu::Config.configure_from_hash(File.basename(yaml_file.sub(/.yml/, '')) => yaml)
  else
    Nezu.logger.info("#{config_file} doesn`t exist. I`m skipping it")
  end
end

.load_configObject

load everything needed to run the app



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/nezu/runtime.rb', line 8

def self.load_config
  configure_from_yaml('database.yml')
  db_config = Nezu::Config.database[Nezu.env]
  begin
    configure_from_yaml('amqp.yml')
  rescue
    Nezu.logger.fatal("[Nezu Runner] no amqp config please create one in config/amqp.yml") unless Nezu::Config.amqp.present?
    raise
  end
  if db_config.database.present? && !Class.const_defined?(:Rails)
    require db_config.adapter
    ActiveRecord::Base.establish_connection(db_config.to_hash)
    ActiveRecord::Base.logger = Logger.new(Nezu.root.join('log/', 'database.log'))
  end

  req_files = Dir.glob(Nezu.root.join('app', 'consumers', '*.rb'))
  req_files += Dir.glob(Nezu.root.join('app', 'producers', '*.rb'))
  unless Class.const_defined?(:Rails)
    req_files += Dir.glob(Nezu.root.join('app', 'models', '*.rb'))
    req_files += Dir.glob(Nezu.root.join('lib', '**', '*.rb'))
  end
   req_files.each do |file_name|
    Nezu.logger.debug("requiring #{file_name}")
    require file_name #Autoload is not thread-safe :(
  end

  app_config=Nezu.root.join('config', 'nezu.rb')
  if File.exist?(app_config)
    require app_config
  else
    Nezu.logger.info("#{app_config} doesn`t exist. I`m skipping it")
  end

  Nezu.logger.debug("[Nezu Runner] config loaded")
  Nezu.logger.debug(Nezu::Config.amqp)
end