about summary refs log tree commit diff
path: root/lib/chewy/strategy/custom_sidekiq.rb
diff options
context:
space:
mode:
authorThibG <thib@sitedethib.com>2019-10-05 18:04:36 +0200
committerGitHub <noreply@github.com>2019-10-05 18:04:36 +0200
commit3921125e5578fb3871fdcae0e8e8a77179f1ad72 (patch)
tree997c8ed2e7a6b8152266edc0c37ea8264c59d1ab /lib/chewy/strategy/custom_sidekiq.rb
parent857c67f31b23b9c496e07eda41755ba449a37f17 (diff)
parentbc8543d9af0045fe2175f7e2234da9c77dc55023 (diff)
Merge pull request #1228 from ThibG/glitch-soc/merge-upstream
Merge upstream changes
Diffstat (limited to 'lib/chewy/strategy/custom_sidekiq.rb')
-rw-r--r--lib/chewy/strategy/custom_sidekiq.rb30
1 files changed, 30 insertions, 0 deletions
diff --git a/lib/chewy/strategy/custom_sidekiq.rb b/lib/chewy/strategy/custom_sidekiq.rb
new file mode 100644
index 000000000..3e54326ba
--- /dev/null
+++ b/lib/chewy/strategy/custom_sidekiq.rb
@@ -0,0 +1,30 @@
+# frozen_string_literal: true
+
+module Chewy
+  class Strategy
+    class CustomSidekiq < Base
+      class Worker
+        include ::Sidekiq::Worker
+
+        sidekiq_options queue: 'pull'
+
+        def perform(type, ids, options = {})
+          options[:refresh] = !Chewy.disable_refresh_async if Chewy.disable_refresh_async
+          type.constantize.import!(ids, options)
+        end
+      end
+
+      def update(type, objects, _options = {})
+        return unless Chewy.enabled?
+
+        ids = type.root.id ? Array.wrap(objects) : type.adapter.identify(objects)
+
+        return if ids.empty?
+
+        Worker.perform_async(type.name, ids)
+      end
+
+      def leave; end
+    end
+  end
+end