Refactor how Redis locks are created (#18400)
* Refactor how Redis locks are created * Fix autorelease duration on account deletion lock
This commit is contained in:
parent
12535568f7
commit
6cf57c6765
16 changed files with 112 additions and 179 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue