blob: 6ce8b5886e8925f156ada21904df2ac4414703b8 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
|
# frozen_string_literal: true
class FetchMediaWorker
include Sidekiq::Worker
sidekiq_options queue: 'bulk', retry: 2
def perform(media_attachment_id, remote_url: nil, force: false)
object = MediaAttachment.find(media_attachment_id.to_i)
return if object&.account.nil? || DomainBlock.reject_media?(object.account.domain)
return unless force || object.needs_redownload?
if remote_url.nil?
return if object.remote_url.nil?
else
object.remote_url = remote_url
end
object.file_remote_url = object.remote_url
object.created_at = Time.now.utc
object.save!
rescue ActiveRecord::RecordNotFound, ActiveRecord::RecordInvalid, HTTP::ConnectionError, Mastodon::UnexpectedResponseError
true
end
end
|