Class: Imports::LoadLines

Inherits:
Object
  • Object
show all
Includes:
Interactor
Defined in:
app/interactors/ntq_excelsior_engine/imports/load_lines.rb

Instance Method Summary collapse

Instance Method Details

#callObject



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'app/interactors/ntq_excelsior_engine/imports/load_lines.rb', line 9

def call
  import = context.import
  importer = context.importer.new
  begin
    import.update(state: 'buffering')

    importer.file = import.temp_file
    lines = importer.lines

    import_lines = []
    lines.each do |line|
      import_lines << NtqExcelsiorEngine::ImportLine.new(line: line, import: import)
    end
    NtqExcelsiorEngine::ImportLine.import(import_lines)
    sleep 2 if NtqExcelsiorEngine.debug
    import.update(headers: importer.detect_header_scheme, state: 'buffered')
    import.temp_file.unlink
  rescue Roo::HeaderRowNotFoundError => e
    import.update(state: 'error', error_message: 'header_not_found', backtrace: e.message)
  rescue StandardError => e
    raise e if NtqExcelsiorEngine.debug

    Appsignal.send_error(e)
    import.update(state: 'error', error_message: e.message, backtrace: e.backtrace.join('\n'))
  end
end