Sha256: 2166a57f99ddf7ac336b7be6ce32478e9dcffbb50e3abd742b15c8d8928fd03d

Contents?: true

Size: 1.15 KB

Versions: 2

Compression:

Stored size: 1.15 KB

Contents

module Importo
  class ImportJob
    include Sidekiq::Job
    sidekiq_options retry: 5
    # queue_as :integration
    queue_as Importo.config.queue_name

    sidekiq_retries_exhausted do |msg, _e|
      attributes = msg["args"][0]
      index = msg["args"][1]
      import_id = msg["args"][2]

      execute_row(attributes, index, import_id, true, msg["bid"])
    end

    sidekiq_retry_in do |_count, exception, _jobhash|
      case exception
      when Importo::RetryError
        exception.delay
      end
    end

    def perform(attributes, index, import_id, bid)
      self.class.execute_row(attributes, index, import_id, false, bid)
    end

    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)
      record = import.importer.process_data_row(attributes, index, last_attempt: last_attempt)

      batch = Importo::SidekiqBatchAdapter.find(bid)

      if !import.completed? && import.can_complete? && batch.finished?
        ImportJobCallback.new.on_success(batch.status, {import_id: import_id})
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
importo-3.0.17 app/jobs/importo/import_job.rb
importo-3.0.16 app/jobs/importo/import_job.rb