indexing_scheduler.rb 679 B

123456789101112131415161718192021222324252627282930
  1. # frozen_string_literal: true
  2. class Scheduler::IndexingScheduler
  3. include Sidekiq::Worker
  4. include Redisable
  5. sidekiq_options retry: 0
  6. IMPORT_BATCH_SIZE = 1000
  7. SCAN_BATCH_SIZE = 10 * IMPORT_BATCH_SIZE
  8. def perform
  9. return unless Chewy.enabled?
  10. indexes.each do |type|
  11. with_redis do |redis|
  12. redis.sscan_each("chewy:queue:#{type.name}", count: SCAN_BATCH_SIZE).each_slice(IMPORT_BATCH_SIZE) do |ids|
  13. type.import!(ids)
  14. redis.pipelined do |pipeline|
  15. pipeline.srem("chewy:queue:#{type.name}", ids)
  16. end
  17. end
  18. end
  19. end
  20. end
  21. def indexes
  22. [AccountsIndex, TagsIndex, StatusesIndex]
  23. end
  24. end