mirror of
https://github.com/mastodon/mastodon.git
synced 2025-09-05 17:31:12 +00:00
26 lines
601 B
Ruby
26 lines
601 B
Ruby
# frozen_string_literal: true
|
|
|
|
class RedownloadMediaWorker
|
|
include Sidekiq::Worker
|
|
include ExponentialBackoff
|
|
include JsonLdHelper
|
|
|
|
sidekiq_options queue: 'pull', retry: 3
|
|
|
|
def perform(id)
|
|
media_attachment = MediaAttachment.find(id)
|
|
|
|
return if media_attachment.remote_url.blank?
|
|
|
|
media_attachment.download_file!
|
|
media_attachment.download_thumbnail!
|
|
media_attachment.save
|
|
rescue ActiveRecord::RecordNotFound
|
|
# Do nothing
|
|
rescue Mastodon::UnexpectedResponseError => e
|
|
response = e.response
|
|
|
|
raise(e) unless response_error_unsalvageable?(response)
|
|
end
|
|
end
|