lib/ImportLogic.rb
## Main import method. Uses an active record transaction (if it fails the whole thing
## is rolled back) to prevent partial importing
Main import method. Uses an active record transaction (if it fails the whole thing
is rolled back) to prevent partial importing
Main import method . Uses an active record transaction ( if it fails the whole thing is rolled back ) to prevent partial importing
def process_CSV_file(file, _total_lines = 0, charset = 'bom|utf-8')
    start_time = Time.now.to_i 
    ActiveRecord::Base.transaction do
      SmarterCSV.process(file, chunk_size: 10, verbose: true, file_encoding: charset.to_s) do |file_chunk|
        file_chunk.each do |record_row|
          sanitized_row = sanitize_row(record_row)
          process_record_row(sanitized_row, {})
          @counter << sanitized_row 
          @updater_actor.run(Celluloid::Actor.current) unless @updater_actor.nil?
          @counter
        end
      end
      total_count = @counter.size
      end_time = Time.now.to_i
      total_count_hash = { total_lines: total_count, time: ((end_time - start_time) / 60).round(2) }
      puts "\033[32m#{total_count_hash}\033[0m\n" 
      @exit_status = 0
      @result = total_count_hash
    end
  ensure
    @updater_actor.terminate unless @updater_actor.nil?
  end
def process_CSV_file ( file , _total_lines = 0 , charset = 'bom|utf-8' ) start_time = Time . now . to_i ActiveRecord :: Base . transaction do SmarterCSV . process ( file , chunk_size : 10 , verbose : true , file_encoding : charset . to_s ) do | file_chunk | file_chunk . each do | record_row | sanitized_row = sanitize_row ( record_row ) process_record_row ( sanitized_row , { } ) @counter << sanitized_row @updater_actor . run ( Celluloid :: Actor . current ) unless @updater_actor . nil? @counter end end total_count = @counter . size end_time = Time . now . to_i total_count_hash = { total_lines : total_count , time : ( ( end_time - start_time ) / 60 ) . round ( 2 ) } puts "\033[32m#{total_count_hash}\033[0m\n" @exit_status = 0 @result = total_count_hash end ensure @updater_actor . terminate unless @updater_actor . nil? end
Main import method.
Main import method .
# setting up time keeping # appends in latest record to allow error to report where import failed ### CallingActorInUpdater feeding it the this (the current) actor. # finishing up time keeping and reporting: # green # on CSV::MalformedCSVError # something gets said
file
_total_lines
charset