diff options
author | shel <Yiskah.Raphen@gmail.com> | 2017-03-31 10:34:14 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-03-31 10:34:14 -0400 |
commit | f20f6b25b98efffca47caae713f8dc5e1d0d4bd1 (patch) | |
tree | 104152d4bd6f9889f38b2f46fee108185c3b29f7 /app/workers/import_worker.rb | |
parent | 76188d61f2c3bb5747208df92835e912db18d7b6 (diff) | |
parent | 680f9efe9c4aa7fce1f4dd6a35ef4aca7a80c1f3 (diff) |
Merge branch 'master' into patch-2
Diffstat (limited to 'app/workers/import_worker.rb')
-rw-r--r-- | app/workers/import_worker.rb | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/app/workers/import_worker.rb b/app/workers/import_worker.rb new file mode 100644 index 000000000..a3ae2a85a --- /dev/null +++ b/app/workers/import_worker.rb @@ -0,0 +1,54 @@ +# frozen_string_literal: true + +require 'csv' + +class ImportWorker + include Sidekiq::Worker + + sidekiq_options retry: false + + def perform(import_id) + import = Import.find(import_id) + + case import.type + when 'blocking' + process_blocks(import) + when 'following' + process_follows(import) + end + + import.destroy + end + + private + + def process_blocks(import) + from_account = import.account + + CSV.foreach(import.data.path) do |row| + next if row.size != 1 + + begin + target_account = FollowRemoteAccountService.new.call(row[0]) + next if target_account.nil? + BlockService.new.call(from_account, target_account) + rescue Goldfinger::Error, HTTP::Error, OpenSSL::SSL::SSLError + next + end + end + end + + def process_follows(import) + from_account = import.account + + CSV.foreach(import.data.path) do |row| + next if row.size != 1 + + begin + FollowService.new.call(from_account, row[0]) + rescue Goldfinger::Error, HTTP::Error, OpenSSL::SSL::SSLError + next + end + end + end +end |