Browse Source

Fix media redownload worker retrying on unexpected response codes (#16111)

closed-social-v3
Eugen Rochko 3 years ago
committed by GitHub
parent
commit
6d9ad30bf8
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 1 deletions
  1. +10
    -1
      app/workers/redownload_media_worker.rb
  2. +4
    -0
      lib/exceptions.rb

+ 10
- 1
app/workers/redownload_media_worker.rb View File

@ -3,6 +3,7 @@
class RedownloadMediaWorker
include Sidekiq::Worker
include ExponentialBackoff
include JsonLdHelper
sidekiq_options queue: 'pull', retry: 3
@ -15,6 +16,14 @@ class RedownloadMediaWorker
media_attachment.download_thumbnail!
media_attachment.save
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

+ 4
- 0
lib/exceptions.rb View File

@ -12,7 +12,11 @@ module Mastodon
class RateLimitExceededError < Error; end
class UnexpectedResponseError < Error
attr_reader :response
def initialize(response = nil)
@response = response
if response.respond_to? :uri
super("#{response.uri} returned code #{response.code}")
else

Loading…
Cancel
Save