indexing_scheduler.rb 645 B

12345678910111213141516171819202122232425262728
  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. indexes.each do |type|
  10. with_redis do |redis|
  11. redis.sscan_each("chewy:queue:#{type.name}", count: SCAN_BATCH_SIZE).each_slice(IMPORT_BATCH_SIZE) do |ids|
  12. type.import!(ids)
  13. redis.pipelined do |pipeline|
  14. pipeline.srem("chewy:queue:#{type.name}", ids)
  15. end
  16. end
  17. end
  18. end
  19. end
  20. def indexes
  21. [AccountsIndex, TagsIndex, StatusesIndex]
  22. end
  23. end