Sha256: 502d0a0c32935657197d0be276bcad039b6ea6013ee889a581662105bfe0b104

Contents?: true

Size: 1.35 KB

Versions: 4

Compression:

Stored size: 1.35 KB

Contents

require 'rubygems'
require 'yaml'

#Determine our working directory
@workingdirectory = File.expand_path(File.dirname(__FILE__))
require @workingdirectory + '/echi-converter.rb'
include EchiConverter

#Open the configuration file
configfile = @workingdirectory + '/../config/application.yml' 
@config = YAML::load(File.open(configfile))

#Load ActiveRecord Models
require @workingdirectory + '/database.rb'

#Load the configured schema
schemafile = @workingdirectory + "/../config/" + @config["echi_schema"]
@echi_schema = YAML::load(File.open(schemafile))

#Open the logfile with appropriate output level
initiate_logger
  
#If configured for database insertion, connect to the database
if @config["export_type"] == 'database' || @config["export_type"] == 'both'
  connect_database
end

@log.info "Running..."

loop do
  #Process the files
  files = fetch_ftp_files
  files.each do | file |
    if @config["echi_format"] == 'BINARY'
      record_cnt = convert_binary_file file
    elsif @config["echi_format"] == 'ASCII'
      record_cnt = process_ascii file
    end
    @log.info "Processed file #{file} with #{record_cnt.to_s} records"
  end

  sleep @config["fetch_interval"]

  #Make sure we did not lose our database connection while we slept
  if ActiveRecord::Base.connected? == 'FALSE'
    connect_database
  end
end

#Close the logfile
@log.info "Shutdown..."
@log.close

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
echi-converter-0.0.4 lib/main.rb
echi-converter-0.0.5 lib/main.rb
echi-converter-0.1.0 lib/main.rb
echi-converter-0.1.1 lib/main.rb