about summary refs log tree commit diff
path: root/app/workers/distribution_worker.rb
diff options
context:
space:
mode:
authorThibG <thib@sitedethib.com>2019-03-16 22:59:47 +0100
committerGitHub <noreply@github.com>2019-03-16 22:59:47 +0100
commit6e3a4bcbc70bb33bfb0746cf3b2186ee9f4e6515 (patch)
tree239e6c3779ce64ee9833c3eec761ea158c2813b3 /app/workers/distribution_worker.rb
parent6af2300454c960ef83f7b7d31e9b829e0d5a8e38 (diff)
parent8ea344fed40ae1dccf5e1b6ecfd0014128c10fb7 (diff)
Merge pull request #962 from ThibG/glitch-soc/merge-upstream
Merge upstream changes
Diffstat (limited to 'app/workers/distribution_worker.rb')
-rw-r--r--app/workers/distribution_worker.rb8
1 files changed, 7 insertions, 1 deletions
diff --git a/app/workers/distribution_worker.rb b/app/workers/distribution_worker.rb
index f423d43ae..4e20ef31b 100644
--- a/app/workers/distribution_worker.rb
+++ b/app/workers/distribution_worker.rb
@@ -4,7 +4,13 @@ class DistributionWorker
   include Sidekiq::Worker
 
   def perform(status_id)
-    FanOutOnWriteService.new.call(Status.find(status_id))
+    RedisLock.acquire(redis: Redis.current, key: "distribute:#{status_id}") do |lock|
+      if lock.acquired?
+        FanOutOnWriteService.new.call(Status.find(status_id))
+      else
+        raise Mastodon::RaceConditionError
+      end
+    end
   rescue ActiveRecord::RecordNotFound
     true
   end