about summary refs log tree commit diff
path: root/app/workers/scheduler/indexing_scheduler.rb
blob: 3a6f47a29a4e13bd416bedbaa3f2504edf13b25f (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
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