indexing_scheduler.rb 717 B

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