about summary refs log tree commit diff
path: root/app/workers
diff options
context:
space:
mode:
authorEugen Rochko <eugen@zeonfederated.com>2019-09-10 15:29:12 +0200
committermultiple creatures <dev@multiple-creature.party>2020-02-21 03:56:30 -0600
commit941c1d41ffebfcd96d6709219c50b1482f930e9b (patch)
treecf0c982dce4f261af2aed71c9fdc7413dd5e0ce2 /app/workers
parent68456c90ce53b5a9852d30ea83d28e14b8c0bac0 (diff)
port tootsuite#11775 to monsterfork: Add retry for failed media downloads and `tootctl media refresh`
Diffstat (limited to 'app/workers')
-rw-r--r--app/workers/redownload_media_worker.rb19
1 files changed, 19 insertions, 0 deletions
diff --git a/app/workers/redownload_media_worker.rb b/app/workers/redownload_media_worker.rb
new file mode 100644
index 000000000..98e995918
--- /dev/null
+++ b/app/workers/redownload_media_worker.rb
@@ -0,0 +1,19 @@
+# frozen_string_literal: true
+
+class RedownloadMediaWorker
+  include Sidekiq::Worker
+  include ExponentialBackoff
+
+  sidekiq_options queue: 'pull', retry: 3
+
+  def perform(id)
+    media_attachment = MediaAttachment.find(id)
+
+    return if media_attachment.remote_url.blank?
+
+    media_attachment.reset_file!
+    media_attachment.save
+  rescue ActiveRecord::RecordNotFound
+    true
+  end
+end