Class: Bulkrax::ExportWorkJob

Inherits:
ApplicationJob show all
Defined in:
app/jobs/bulkrax/export_work_job.rb

Instance Method Summary collapse

Instance Method Details

#perform(*args) ⇒ Object



7
8
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
35
36
37
38
# File 'app/jobs/bulkrax/export_work_job.rb', line 7

def perform(*args)
  entry = Entry.find(args[0])
  exporter_run = ExporterRun.find(args[1])
  begin
    entry.build
    entry.save
  rescue StandardError
    # rubocop:disable Rails/SkipsModelValidations
    ExporterRun.increment_counter(:failed_records, args[1])
    ExporterRun.decrement_counter(:enqueued_records, args[1]) unless exporter_run.reload.enqueued_records <= 0
    raise
  else
    if entry.failed?
      ExporterRun.increment_counter(:failed_records, args[1])
      ExporterRun.decrement_counter(:enqueued_records, args[1]) unless exporter_run.reload.enqueued_records <= 0
      raise entry.reload.current_status.error_class.constantize
    else
      ExporterRun.increment_counter(:processed_records, args[1])
      ExporterRun.decrement_counter(:enqueued_records, args[1]) unless exporter_run.reload.enqueued_records <= 0
    end
    # rubocop:enable Rails/SkipsModelValidations
  end
  return entry if exporter_run.enqueued_records.positive?

  if exporter_run.failed_records.positive?
    exporter_run.exporter.set_status_info('Complete (with failures)')
  else
    exporter_run.exporter.set_status_info('Complete')
  end

  return entry
end