about summary refs log tree commit diff
path: root/app/workers/post_process_media_worker.rb
diff options
context:
space:
mode:
authorThibG <thib@sitedethib.com>2020-03-22 17:59:47 +0100
committerGitHub <noreply@github.com>2020-03-22 17:59:47 +0100
commitd101438b9d1bd827c191605cb21d58f83de2124d (patch)
treeb36d73f45175add7aa114bb42fca5a528a9b24a4 /app/workers/post_process_media_worker.rb
parent7115b0b8c99b7e88aee264be75945e592dec33e4 (diff)
parent9da4bd098cac88c3e44157765adcff01445ba31a (diff)
Merge pull request #1305 from ThibG/glitch-soc/merge-upstream
Merge upstream changes
Diffstat (limited to 'app/workers/post_process_media_worker.rb')
-rw-r--r--app/workers/post_process_media_worker.rb34
1 files changed, 34 insertions, 0 deletions
diff --git a/app/workers/post_process_media_worker.rb b/app/workers/post_process_media_worker.rb
new file mode 100644
index 000000000..d3ebda194
--- /dev/null
+++ b/app/workers/post_process_media_worker.rb
@@ -0,0 +1,34 @@
+# frozen_string_literal: true
+
+class PostProcessMediaWorker
+  include Sidekiq::Worker
+
+  sidekiq_options retry: 1, dead: false
+
+  sidekiq_retries_exhausted do |msg|
+    media_attachment_id = msg['args'].first
+
+    ActiveRecord::Base.connection_pool.with_connection do
+      begin
+        media_attachment = MediaAttachment.find(media_attachment_id)
+        media_attachment.processing = :failed
+        media_attachment.save
+      rescue ActiveRecord::RecordNotFound
+        true
+      end
+    end
+
+    Sidekiq.logger.error("Processing media attachment #{media_attachment_id} failed with #{msg['error_message']}")
+  end
+
+  def perform(media_attachment_id)
+    media_attachment = MediaAttachment.find(media_attachment_id)
+    media_attachment.processing = :in_progress
+    media_attachment.save
+    media_attachment.file.reprocess_original!
+    media_attachment.processing = :complete
+    media_attachment.save
+  rescue ActiveRecord::RecordNotFound
+    true
+  end
+end