redownload_media_worker.rb 635 B

1234567891011121314151617181920212223242526272829
  1. # frozen_string_literal: true
  2. class RedownloadMediaWorker
  3. include Sidekiq::Worker
  4. include ExponentialBackoff
  5. include JsonLdHelper
  6. sidekiq_options queue: 'pull', retry: 3
  7. def perform(id)
  8. media_attachment = MediaAttachment.find(id)
  9. return if media_attachment.remote_url.blank?
  10. media_attachment.download_file!
  11. media_attachment.download_thumbnail!
  12. media_attachment.save
  13. rescue ActiveRecord::RecordNotFound
  14. # Do nothing
  15. rescue Mastodon::UnexpectedResponseError => e
  16. response = e.response
  17. if response_error_unsalvageable?(response)
  18. # Give up
  19. else
  20. raise e
  21. end
  22. end
  23. end