indexing_scheduler.rb 728 B

1234567891011121314151617181920212223242526272829303132
  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. private
  21. def indexes
  22. [AccountsIndex, TagsIndex, PublicStatusesIndex, StatusesIndex]
  23. end
  24. end