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
683 B

  1. # frozen_string_literal: true
  2. class RedownloadAvatarWorker
  3. include Sidekiq::Worker
  4. include ExponentialBackoff
  5. include JsonLdHelper
  6. sidekiq_options queue: 'pull', retry: 7
  7. def perform(id)
  8. account = Account.find(id)
  9. return if account.suspended? || DomainBlock.rule_for(account.domain)&.reject_media?
  10. return if account.avatar_remote_url.blank? || account.avatar_file_name.present?
  11. account.reset_avatar!
  12. account.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