diff options
author | multiple creatures <dev@multiple-creature.party> | 2019-08-30 19:31:14 -0500 |
---|---|---|
committer | multiple creatures <dev@multiple-creature.party> | 2019-08-30 19:31:57 -0500 |
commit | e881d75632898d1544962fa5f38f418ab0ab152f (patch) | |
tree | 85d661098c727a2d29ed14cf036e1ed04982a7c6 /app/workers | |
parent | 90ffbb0ada5c81451742e66635bc54eb0f7716f2 (diff) |
(asynchronously) re-fetch missing media on serialize
Diffstat (limited to 'app/workers')
-rw-r--r-- | app/workers/domain_block_worker.rb | 3 | ||||
-rw-r--r-- | app/workers/fetch_media_worker.rb | 19 |
2 files changed, 21 insertions, 1 deletions
diff --git a/app/workers/domain_block_worker.rb b/app/workers/domain_block_worker.rb index 884477829..d51c387dc 100644 --- a/app/workers/domain_block_worker.rb +++ b/app/workers/domain_block_worker.rb @@ -4,7 +4,8 @@ class DomainBlockWorker include Sidekiq::Worker def perform(domain_block_id) - BlockDomainService.new.call(DomainBlock.find(domain_block_id)) + domain_block = DomainBlock.find(domain_block_id) + BlockDomainService.new.call(domain_block) rescue ActiveRecord::RecordNotFound true end diff --git a/app/workers/fetch_media_worker.rb b/app/workers/fetch_media_worker.rb new file mode 100644 index 000000000..5dc8cc84b --- /dev/null +++ b/app/workers/fetch_media_worker.rb @@ -0,0 +1,19 @@ +# frozen_string_literal: true + +class FetchMediaWorker + include Sidekiq::Worker + + def perform(media_attachment_id, remote_url = nil) + object = MediaAttachment.find(media_attachment_id.to_i) + 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 + true + end +end |