1
0

custom_sidekiq.rb 685 B

123456789101112131415161718192021222324252627282930
  1. # frozen_string_literal: true
  2. module Chewy
  3. class Strategy
  4. class CustomSidekiq < Base
  5. class Worker
  6. include ::Sidekiq::Worker
  7. sidekiq_options queue: 'pull'
  8. def perform(type, ids, options = {})
  9. options[:refresh] = !Chewy.disable_refresh_async if Chewy.disable_refresh_async
  10. type.constantize.import!(ids, options)
  11. end
  12. end
  13. def update(type, objects, _options = {})
  14. return unless Chewy.enabled?
  15. ids = type.root.id ? Array.wrap(objects) : type.adapter.identify(objects)
  16. return if ids.empty?
  17. Worker.perform_async(type.name, ids)
  18. end
  19. def leave; end
  20. end
  21. end
  22. end