From 6cf57c676550068a59149ca82d63fcb5b5431158 Mon Sep 17 00:00:00 2001 From: Eugen Rochko Date: Fri, 13 May 2022 00:02:35 +0200 Subject: Refactor how Redis locks are created (#18400) * Refactor how Redis locks are created * Fix autorelease duration on account deletion lock --- app/workers/distribution_worker.rb | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) (limited to 'app/workers') diff --git a/app/workers/distribution_worker.rb b/app/workers/distribution_worker.rb index 474b4daaf..59cdbc7b2 100644 --- a/app/workers/distribution_worker.rb +++ b/app/workers/distribution_worker.rb @@ -3,14 +3,11 @@ class DistributionWorker include Sidekiq::Worker include Redisable + include Lockable def perform(status_id, options = {}) - RedisLock.acquire(redis: redis, key: "distribute:#{status_id}", autorelease: 5.minutes.seconds) do |lock| - if lock.acquired? - FanOutOnWriteService.new.call(Status.find(status_id), **options.symbolize_keys) - else - raise Mastodon::RaceConditionError - end + with_lock("distribute:#{status_id}") do + FanOutOnWriteService.new.call(Status.find(status_id), **options.symbolize_keys) end rescue ActiveRecord::RecordNotFound true -- cgit