Class: Chewy::Strategy::DelayedSidekiq
- Defined in:
- lib/chewy/strategy/delayed_sidekiq.rb,
lib/chewy/strategy/delayed_sidekiq/worker.rb,
lib/chewy/strategy/delayed_sidekiq/scheduler.rb
Defined Under Namespace
Constant Summary collapse
- LUA_SCRIPT =
<<~LUA local timechunk_key = KEYS[1] local timechunks_key = KEYS[2] local serialize_data = ARGV[1] local at = ARGV[2] local ttl = tonumber(ARGV[3]) local schedule_job = false -- Check if the 'sadd?' method is available if redis.call('exists', 'sadd?') == 1 then redis.call('sadd?', timechunk_key, serialize_data) else redis.call('sadd', timechunk_key, serialize_data) end -- Set expiration for timechunk_key redis.call('expire', timechunk_key, ttl) -- Check if timechunk_key exists in the sorted set if not redis.call('zrank', timechunks_key, timechunk_key) then -- Add timechunk_key to the sorted set redis.call('zadd', timechunks_key, at, timechunk_key) -- Set expiration for timechunks_key redis.call('expire', timechunks_key, ttl) schedule_job = true end return schedule_job LUA
Class Method Summary collapse
-
.clear_timechunks! ⇒ Object
cleanup the redis sets used internally.
Instance Method Summary collapse
Methods inherited from Atomic
Methods inherited from Base
#name, #update, #update_chewy_indices
Constructor Details
This class inherits a constructor from Chewy::Strategy::Atomic
Class Method Details
.clear_timechunks! ⇒ Object
cleanup the redis sets used internally. Useful mainly in tests to avoid leak and potential flaky tests.
10 11 12 13 14 15 16 17 18 19 |
# File 'lib/chewy/strategy/delayed_sidekiq.rb', line 10 def self.clear_timechunks! ::Sidekiq.redis do |redis| keys_to_delete = redis.keys("#{Scheduler::KEY_PREFIX}*") # Delete keys one by one keys_to_delete.each do |key| redis.del(key) end end end |
Instance Method Details
#leave ⇒ Object
21 22 23 24 25 26 27 |
# File 'lib/chewy/strategy/delayed_sidekiq.rb', line 21 def leave @stash.each do |type, ids| next if ids.empty? DelayedSidekiq::Scheduler.new(type, ids).postpone end end |