Class: Renalware::UKRDC::Incoming::ImportSurveys

Inherits:
Object
  • Object
show all
Defined in:
app/models/renalware/ukrdc/incoming/import_surveys.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(paths: nil, logger: nil) ⇒ ImportSurveys

Returns a new instance of ImportSurveys.



12
13
14
15
16
# File 'app/models/renalware/ukrdc/incoming/import_surveys.rb', line 12

def initialize(paths: nil, logger: nil)
  @paths = paths || Renalware::UKRDC::Incoming::Paths.new
  @logger = logger || Rails.logger
  @batch_uuid = SecureRandom.uuid # to group logging output
end

Instance Attribute Details

#batch_uuidObject (readonly)

Returns the value of attribute batch_uuid.



10
11
12
# File 'app/models/renalware/ukrdc/incoming/import_surveys.rb', line 10

def batch_uuid
  @batch_uuid
end

Instance Method Details

#callObject



18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'app/models/renalware/ukrdc/incoming/import_surveys.rb', line 18

def call
  Incoming::FileList.new(paths: paths).each_file do |filepath|
    if already_imported?(filepath)
      logger.info "Skipping: #{filepath} already successfully imported"
      FileUtils.mv filepath, paths.archive.join(filepath.basename)
      next
    end
    logger.info "Processing: #{filepath}"
    import_surveys_from_file(filepath)
  end
rescue StandardError => e
  Renalware::Engine.exception_notifier.notify(e)
  raise e
end