about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--app/workers/batch_fetch_media_worker.rb14
1 files changed, 14 insertions, 0 deletions
diff --git a/app/workers/batch_fetch_media_worker.rb b/app/workers/batch_fetch_media_worker.rb
new file mode 100644
index 000000000..c002aeee7
--- /dev/null
+++ b/app/workers/batch_fetch_media_worker.rb
@@ -0,0 +1,14 @@
+# frozen_string_literal: true
+
+class BatchFetchMediaWorker
+  include Sidekiq::Worker
+
+  sidekiq_options queue: 'bulk', retry: 2
+
+  def perform(media_attachment_ids)
+    media_attachment_ids.each_with_index do |attachment_id, index|
+      FetchMediaWorker.perform_async(attachment_id)
+      sleep(0.5 * Sidekiq::Queue.new(:bulk).size)
+    end
+  end
+end