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 =
"local timechunk_key = KEYS[1]\nlocal timechunks_key = KEYS[2]\nlocal serialize_data = ARGV[1]\nlocal at = ARGV[2]\nlocal ttl = tonumber(ARGV[3])\n\nlocal schedule_job = false\n\n-- Check if the 'sadd?' method is available\nif redis.call('exists', 'sadd?') == 1 then\n redis.call('sadd?', timechunk_key, serialize_data)\nelse\n redis.call('sadd', timechunk_key, serialize_data)\nend\n\n-- Set expiration for timechunk_key\nredis.call('expire', timechunk_key, ttl)\n\n-- Check if timechunk_key exists in the sorted set\nif not redis.call('zrank', timechunks_key, timechunk_key) then\n -- Add timechunk_key to the sorted set\n redis.call('zadd', timechunks_key, at, timechunk_key)\n -- Set expiration for timechunks_key\n redis.call('expire', timechunks_key, ttl)\n schedule_job = true\nend\n\nreturn schedule_job\n"
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 |