You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

29 lines
635 B

  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