about summary refs log tree commit diff
path: root/app/workers/scheduler
diff options
context:
space:
mode:
authorClaire <claire.github-309c@sitedethib.com>2022-05-24 13:59:21 +0200
committerClaire <claire.github-309c@sitedethib.com>2022-05-24 13:59:21 +0200
commit22111914bfc838a43bb2e20244c965467f127de2 (patch)
tree8f6301da32a36a3ebeec0b965a74f67c02632f7c /app/workers/scheduler
parentc279dbd47082e908d98dc8cf869c0ff7fc19f1ae (diff)
parente5997a195602624efdb366e9f09ffa377e859580 (diff)
Merge branch 'main' into glitch-soc/merge-upstream
Diffstat (limited to 'app/workers/scheduler')
-rw-r--r--app/workers/scheduler/indexing_scheduler.rb26
1 files changed, 26 insertions, 0 deletions
diff --git a/app/workers/scheduler/indexing_scheduler.rb b/app/workers/scheduler/indexing_scheduler.rb
new file mode 100644
index 000000000..3a6f47a29
--- /dev/null
+++ b/app/workers/scheduler/indexing_scheduler.rb
@@ -0,0 +1,26 @@
+# frozen_string_literal: true
+
+class Scheduler::IndexingScheduler
+  include Sidekiq::Worker
+  include Redisable
+
+  sidekiq_options retry: 0
+
+  def perform
+    indexes.each do |type|
+      with_redis do |redis|
+        ids = redis.smembers("chewy:queue:#{type.name}")
+
+        type.import!(ids)
+
+        redis.pipelined do |pipeline|
+          ids.each { |id| pipeline.srem("chewy:queue:#{type.name}", id) }
+        end
+      end
+    end
+  end
+
+  def indexes
+    [AccountsIndex, TagsIndex, StatusesIndex]
+  end
+end