Sha256: d8e4343ff61452739e93d898fe97b326983c81be32c945ed4f2a19700ecd4ce2

Contents?: true

Size: 1.79 KB

Versions: 7

Compression:

Stored size: 1.79 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)
    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

7 entries across 7 versions & 1 rubygems

Version Path
daengine-0.2.1 lib/daengine.rb
daengine-0.1.9 lib/daengine.rb
daengine-0.1.8 lib/daengine.rb
daengine-0.1.7 lib/daengine.rb
daengine-0.1.6 lib/daengine.rb
daengine-0.1.5 lib/daengine.rb
daengine-0.1.4 lib/daengine.rb