lib/main.rb in echi-converter-0.1.1 vs lib/main.rb in echi-converter-0.2.0

- old
+ new

@@ -9,11 +9,15 @@ #Open the configuration file configfile = @workingdirectory + '/../config/application.yml' @config = YAML::load(File.open(configfile)) #Load ActiveRecord Models -require @workingdirectory + '/database.rb' +if @config["pco_process"] == 'Y' + require @workingdirectory + '/database_presence.rb' +else + require @workingdirectory + '/database.rb' +end #Load the configured schema schemafile = @workingdirectory + "/../config/" + @config["echi_schema"] @echi_schema = YAML::load(File.open(schemafile)) @@ -27,15 +31,24 @@ @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 + ftp_files = fetch_ftp_files + #Grab filenames from the to_process directory after an FTP fetch, so if the + #system fails it may pick up where it left off + to_process_dir = @workingdirectory + "/../files/to_process/" + + #Establish where to copy the processed files to + @processeddirectory = set_directory(@workingdirectory) + + Dir.entries(to_process_dir).each do | file | + if file != "." && file != ".." + if @config["echi_format"] == 'BINARY' + record_cnt = convert_binary_file file + elsif @config["echi_format"] == 'ASCII' + record_cnt = process_ascii file + end end @log.info "Processed file #{file} with #{record_cnt.to_s} records" end sleep @config["fetch_interval"] \ No newline at end of file