row_worker.rb 930 B

123456789101112131415161718192021222324252627282930313233
  1. # frozen_string_literal: true
  2. class Import::RowWorker
  3. include Sidekiq::Worker
  4. sidekiq_options queue: 'pull', retry: 6, dead: false
  5. sidekiq_retries_exhausted do |msg, _exception|
  6. ActiveRecord::Base.connection_pool.with_connection do
  7. # Increment the total number of processed items, and bump the state of the import if needed
  8. bulk_import_id = BulkImportRow.where(id: msg['args'][0]).pick(:bulk_import_id)
  9. BulkImport.progress!(bulk_import_id) unless bulk_import_id.nil?
  10. end
  11. end
  12. def perform(row_id)
  13. row = BulkImportRow.eager_load(bulk_import: :account).find_by(id: row_id)
  14. return true if row.nil?
  15. imported = BulkImportRowService.new.call(row)
  16. mark_as_processed!(row, imported)
  17. end
  18. private
  19. def mark_as_processed!(row, imported)
  20. bulk_import_id = row.bulk_import_id
  21. row.destroy! if imported
  22. BulkImport.progress!(bulk_import_id, imported: imported)
  23. end
  24. end