about summary refs log tree commit diff
diff options
context:
space:
mode:
authormultiple creatures <dev@multiple-creature.party>2019-09-17 21:23:09 -0500
committermultiple creatures <dev@multiple-creature.party>2019-09-17 21:23:09 -0500
commite2f7f1db860c45112ce9c94859bc19cd53cab773 (patch)
treeaeb48f03924bd56026dee5fcd9aabfa0da33c45d
parent750fb3d8b1355719be189ef7de13b728cddd2268 (diff)
add `BatchFetchMediaWorker` to fetch batches of media without overloading either server
-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