about summary refs log tree commit diff
path: root/app/workers/import
diff options
context:
space:
mode:
authorEugen Rochko <eugen@zeonfederated.com>2017-10-04 00:39:32 +0200
committerGitHub <noreply@github.com>2017-10-04 00:39:32 +0200
commitcdd5ef691bcdb25f8c8367698de7e09301ee3528 (patch)
treed94c941fe02d35a81b590e7a2c3a8e53d22c8e12 /app/workers/import
parentc743b5e1fdb938d52d8c023bb6ef1bf9b397226c (diff)
Use separate workers to process imports, retry failures (#5207)
Diffstat (limited to 'app/workers/import')
-rw-r--r--app/workers/import/relationship_worker.rb25
1 files changed, 25 insertions, 0 deletions
diff --git a/app/workers/import/relationship_worker.rb b/app/workers/import/relationship_worker.rb
new file mode 100644
index 000000000..ed4c962c1
--- /dev/null
+++ b/app/workers/import/relationship_worker.rb
@@ -0,0 +1,25 @@
+# frozen_string_literal: true
+
+class Import::RelationshipWorker
+  include Sidekiq::Worker
+
+  sidekiq_options queue: 'pull', retry: 8, dead: false
+
+  def perform(account_id, target_account_uri, relationship)
+    from_account   = Account.find(account_id)
+    target_account = ResolveRemoteAccountService.new.call(target_account_uri)
+
+    return if target_account.nil?
+
+    case relationship
+    when 'follow'
+      FollowService.new.call(from_account, target_account.acct)
+    when 'block'
+      BlockService.new.call(from_account, target_account)
+    when 'mute'
+      MuteService.new.call(from_account, target_account)
+    end
+  rescue ActiveRecord::RecordNotFound
+    true
+  end
+end