Raise Mastodon::RaceConditionError if Redis lock failed (#7511)

An explicit error allows user agents to know the error and Sidekiq to
retry.
This commit is contained in:
Akihiko Odaki 2018-05-16 19:29:45 +09:00 committed by Eugen Rochko
parent 7dd6224ca1
commit 5dadb6896b
6 changed files with 12 additions and 0 deletions

View file

@ -8,6 +8,8 @@ class MediaProxyController < ApplicationController
if lock.acquired? if lock.acquired?
@media_attachment = MediaAttachment.remote.find(params[:id]) @media_attachment = MediaAttachment.remote.find(params[:id])
redownload! if @media_attachment.needs_redownload? && !reject_media? redownload! if @media_attachment.needs_redownload? && !reject_media?
else
raise Mastodon::RaceConditionError
end end
end end

View file

@ -11,6 +11,8 @@ class ActivityPub::Activity::Create < ActivityPub::Activity
if lock.acquired? if lock.acquired?
@status = find_existing_status @status = find_existing_status
process_status if @status.nil? process_status if @status.nil?
else
raise Mastodon::RaceConditionError
end end
end end

View file

@ -15,6 +15,8 @@ class OStatus::Activity::Creation < OStatus::Activity::Base
@status = find_status(id) @status = find_status(id)
return [@status, false] unless @status.nil? return [@status, false] unless @status.nil?
@status = process_status @status = process_status
else
raise Mastodon::RaceConditionError
end end
end end

View file

@ -23,6 +23,8 @@ class ActivityPub::ProcessAccountService < BaseService
create_account if @account.nil? create_account if @account.nil?
update_account update_account
process_tags process_tags
else
raise Mastodon::RaceConditionError
end end
end end

View file

@ -23,6 +23,8 @@ class FetchLinkCardService < BaseService
if lock.acquired? if lock.acquired?
@card = PreviewCard.find_by(url: @url) @card = PreviewCard.find_by(url: @url)
process_url if @card.nil? || @card.updated_at <= 2.weeks.ago process_url if @card.nil? || @card.updated_at <= 2.weeks.ago
else
raise Mastodon::RaceConditionError
end end
end end

View file

@ -49,6 +49,8 @@ class ResolveAccountService < BaseService
else else
handle_ostatus handle_ostatus
end end
else
raise Mastodon::RaceConditionError
end end
end end