Fix media redownload worker retrying on unexpected response codes (#16111)
This commit is contained in:
parent
a6e9c41ed4
commit
64d9b84f1d
2 changed files with 14 additions and 1 deletions
|
@ -12,7 +12,11 @@ module Mastodon
|
||||||
class RateLimitExceededError < Error; end
|
class RateLimitExceededError < Error; end
|
||||||
|
|
||||||
class UnexpectedResponseError < Error
|
class UnexpectedResponseError < Error
|
||||||
|
attr_reader :response
|
||||||
|
|
||||||
def initialize(response = nil)
|
def initialize(response = nil)
|
||||||
|
@response = response
|
||||||
|
|
||||||
if response.respond_to? :uri
|
if response.respond_to? :uri
|
||||||
super("#{response.uri} returned code #{response.code}")
|
super("#{response.uri} returned code #{response.code}")
|
||||||
else
|
else
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
class RedownloadMediaWorker
|
class RedownloadMediaWorker
|
||||||
include Sidekiq::Worker
|
include Sidekiq::Worker
|
||||||
include ExponentialBackoff
|
include ExponentialBackoff
|
||||||
|
include JsonLdHelper
|
||||||
|
|
||||||
sidekiq_options queue: 'pull', retry: 3
|
sidekiq_options queue: 'pull', retry: 3
|
||||||
|
|
||||||
|
@ -15,6 +16,14 @@ class RedownloadMediaWorker
|
||||||
media_attachment.download_thumbnail!
|
media_attachment.download_thumbnail!
|
||||||
media_attachment.save
|
media_attachment.save
|
||||||
rescue ActiveRecord::RecordNotFound
|
rescue ActiveRecord::RecordNotFound
|
||||||
true
|
# Do nothing
|
||||||
|
rescue Mastodon::UnexpectedResponseError => e
|
||||||
|
response = e.response
|
||||||
|
|
||||||
|
if response_error_unsalvageable?(response)
|
||||||
|
# Give up
|
||||||
|
else
|
||||||
|
raise e
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue