Module: RedisQueuedLocks::Acquirer::ClearDeadRequests Private

Defined in:
lib/redis_queued_locks/acquirer/clear_dead_requests.rb

Overview

This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.

Since:

  • 1.0.0

Class Method Summary collapse

Class Method Details

.clear_dead_requests(redis_client, scan_size, dead_ttl, logger, instrumenter, instrument, log_sampling_enabled, log_sampling_percent, log_sampler, log_sample_this, instr_sampling_enabled, instr_sampling_percent, instr_sampler, instr_sample_this) ⇒ Hash<Symbol,Boolean|Hash<Symbol,Set<String>>>

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Parameters:

  • redis_client (RedisClient)
  • scan_size (Integer)
  • dead_ttl (Integer) —

    In milliseconds

  • logger (::Logger, #debug)
  • instrumenter (#notify)
  • instrument (NilClass, Any)
  • log_sampling_enabled (Boolean)
  • log_sampling_percent (Integer)
  • log_sampler (#sampling_happened?, Module<RedisQueuedLocks::Logging::Sampler>)
  • log_sample_this (Boolean)
  • instr_sampling_enabled (Boolean)
  • instr_sampling_percent (Integer)
  • instr_sampler (#sampling_happened?, Module<RedisQueuedLocks::Instrument::Sampler>)
  • instr_sample_this (Boolean)

Returns:

  • (Hash<Symbol,Boolean|Hash<Symbol,Set<String>>>)

Since:

  • 1.0.0

Version:

  • 1.6.0



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/redis_queued_locks/acquirer/clear_dead_requests.rb', line 26

def clear_dead_requests(
  redis_client,
  scan_size,
  dead_ttl,
  logger,
  instrumenter,
  instrument,
  log_sampling_enabled,
  log_sampling_percent,
  log_sampler,
  log_sample_this,
  instr_sampling_enabled,
  instr_sampling_percent,
  instr_sampler,
  instr_sample_this
)
  dead_score = RedisQueuedLocks::Resource.acquirer_dead_score(dead_ttl / 1_000.0)

  # @type var result: Set[String]
  result = Set.new.tap do |processed_queues|
    # @type var processed_queues: Set[String]
    redis_client.with do |rconn|
      each_lock_queue(rconn, scan_size) do |lock_queue|
        rconn.call('ZREMRANGEBYSCORE', lock_queue, '-inf', dead_score)
        processed_queues << lock_queue
      end
    end
  end

  { ok: true, result: { processed_queues: result } }
end