Class: Bulkrax::ImportFileSetJob

Inherits:
ApplicationJob show all
Includes:
DynamicRecordLookup
Defined in:
app/jobs/bulkrax/import_file_set_job.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from DynamicRecordLookup

#find_record

Instance Attribute Details

#importer_run_idObject (readonly)

Returns the value of attribute importer_run_id.



11
12
13
# File 'app/jobs/bulkrax/import_file_set_job.rb', line 11

def importer_run_id
  @importer_run_id
end

Instance Method Details

#perform(entry_id, importer_run_id) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'app/jobs/bulkrax/import_file_set_job.rb', line 13

def perform(entry_id, importer_run_id)
  @importer_run_id = importer_run_id
  entry = Entry.find(entry_id)
  # e.g. "parents" or "parents_1"
  parent_identifier = (entry.[entry.related_parents_raw_mapping] || entry.["#{entry.related_parents_raw_mapping}_1"])&.strip

  validate_parent!(parent_identifier)

  entry.build
  if entry.succeeded?
    # rubocop:disable Rails/SkipsModelValidations
    ImporterRun.increment_counter(:processed_records, importer_run_id)
    ImporterRun.increment_counter(:processed_file_sets, importer_run_id)
  else
    ImporterRun.increment_counter(:failed_records, importer_run_id)
    ImporterRun.increment_counter(:failed_file_sets, importer_run_id)
    # rubocop:enable Rails/SkipsModelValidations
  end
  ImporterRun.decrement_counter(:enqueued_records, importer_run_id) unless ImporterRun.find(importer_run_id).enqueued_records <= 0 # rubocop:disable Rails/SkipsModelValidations
  entry.save!
  entry.importer.current_run = ImporterRun.find(importer_run_id)
  entry.importer.record_status

rescue MissingParentError => e
  # try waiting for the parent record to be created
  entry.import_attempts += 1
  entry.save!
  if entry.import_attempts < 5
    ImportFileSetJob.set(wait: (entry.import_attempts + 1).minutes).perform_later(entry_id, importer_run_id)
  else
    ImporterRun.decrement_counter(:enqueued_records, importer_run_id) # rubocop:disable Rails/SkipsModelValidations
    entry.set_status_info(e)
  end
end