Sha256: 86179e4db82369034f33859103d14b187baf699295040a18a309c478c10f25dd

Contents?: true

Size: 1.87 KB

Versions: 1

Compression:

Stored size: 1.87 KB

Contents

require "daengine/version"
require 'daengine/engine'
require File.expand_path('../../app/models/digital_asset',__FILE__)
require 'daengine/teamsite_metadata_parser'
require 'daengine/digital_asset_processor'
require 'mongoid'
require 'logger'

module Daengine
  @logger = "/logs/daengine.log"

  @config = {
    :assets_path => '/digital-assets'
  }

  @mongoid_config = {
    'database' => 'ssc_assets', # mongoid database name
    'host' => nil, # mongoid server
    'port' => nil, # mongodb server port
    'hosts' => nil
  }

  @valid_mongoid_keys = @mongoid_config.keys

  def self.log(message, level)
    message = "[#{Time.now.strftime("%Y-%m-%d %H:%M:%S")}] #{message}"
    puts "#{message}"
    case level
      when "warn"
         @logger.warn "#{message}"
      when "error"
        @logger.error "#{message}"
      else
        @logger.info "#{message}"
    end
  end

  # yaml file config
  def self.configure(config_options)
    config_options.each {|k,v| @config[k.to_sym] = v}
    config_options.each {|k,v| 
      @mongoid_config[k] = v if @valid_mongoid_keys.include? k
    }
    @mongoid_config.delete_if { |k,v| ! v }
    Mongoid.configure do |config|
      config.from_hash(@mongoid_config)
    end
  end

  def self.config
    @config
  end

  def self.execute()
    config_options = YAML.load_file('C:\dev\529-workspace\rails\daengine\client\config.yml')
    self.configure(config_options)
    self.set_logger()
    self.log("Daengine: ### Loading application config ###", "info")
    config_options.each { |key, value| self.log("CONFIG #{key}\t#{value}", "info")}
    begin
      DigitalAssetProcessor.process_tuple_directory  # start the thread daemon
    rescue Exception => e
      self.log(e.message, "error")
    end
  end

  def self.set_logger
    logfile = self.config[:logfile_location]
    @logger = Logger.new(logfile, 'daily')
  end

  def self.logger
    @logger
  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
daengine-0.2.0 lib/daengine.rb