Class: Importo::ImportJob

Inherits:
Object
  • Object
show all
Defined in:
app/jobs/importo/import_job.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.execute_row(attributes, index, import_id, last_attempt, bid) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'app/jobs/importo/import_job.rb', line 24

def self.execute_row(attributes, index, import_id, last_attempt, bid)
  attributes = JSON.load(attributes).deep_symbolize_keys if attributes.is_a?(String)

  import = Import.find(import_id)
  import.importer.process_data_row(attributes, index, last_attempt: last_attempt)

  # Between sidekiq and good job, there's a big difference:
  # - Sidekiq calls on_complete callback when all jobs ran at least once.
  # - GoodJob calls on_complete callback when all jobs are done (including retries).
  # i.e. this logic is only needed for sidekiq
  if Importo.config.batch_adapter == Importo::SidekiqBatchAdapter
    batch = Importo::SidekiqBatchAdapter.find(bid)

    if !import.completed? && import.can_complete? && batch.finished?
      ImportJobCallback.perform_now(batch, import.id)
    end
  end
end

Instance Method Details

#perform(attributes, index, import_id) ⇒ Object

No options here, gets added from the adapter



13
14
15
16
17
18
19
20
21
22
# File 'app/jobs/importo/import_job.rb', line 13

def perform(attributes, index, import_id)
  batch_id = if defined?(bid)
    bid
  else
    batch.id
  end
  batch

  self.class.execute_row(attributes, index, import_id, false, batch_id)
end