import_worker.rb 706 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. # frozen_string_literal: true
  2. require 'csv'
  3. class ImportWorker
  4. include Sidekiq::Worker
  5. sidekiq_options queue: 'pull', retry: false
  6. attr_reader :import
  7. def perform(import_id)
  8. @import = Import.find(import_id)
  9. Import::RelationshipWorker.push_bulk(import_rows) do |row|
  10. [@import.account_id, row.first, relationship_type]
  11. end
  12. @import.destroy
  13. end
  14. private
  15. def import_contents
  16. Paperclip.io_adapters.for(@import.data).read
  17. end
  18. def relationship_type
  19. case @import.type
  20. when 'following'
  21. 'follow'
  22. when 'blocking'
  23. 'block'
  24. when 'muting'
  25. 'mute'
  26. end
  27. end
  28. def import_rows
  29. CSV.new(import_contents).reject(&:blank?)
  30. end
  31. end