Module: RedisQueuedLocks::Swarm::Acquirers Private

Defined in:
lib/redis_queued_locks/swarm/acquirers.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.9.0

Class Method Summary collapse

Class Method Details

.acquirers(redis_client, zombie_ttl) ⇒ Hash<String,Hash<Symbol,Float|Time>>

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.

Returns the list of swarm acquirers stored as HASH. Liveness probe time is represented as a float value (Time.now.to_f initially).

Parameters:

  • redis_client (RedisClient)
  • zombie_ttl (Integer)

Returns:

  • (Hash<String,Hash<Symbol,Float|Time>>) —

    Format: { <acquirer id #1> => { zombie: , last_probe_time:

Since:

  • 1.9.0



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/redis_queued_locks/swarm/acquirers.rb', line 29

def acquirers(redis_client, zombie_ttl)
  redis_client.with do |rconn|
    rconn.call('HGETALL', RedisQueuedLocks::Resource::SWARM_KEY).tap do |swarm_acqs|
      # @type var swarm_acqs: Hash[String,untyped]
      swarm_acqs.transform_values! do |last_probe|
        # @type var last_probe: String
        last_probe_score = last_probe.to_f
        last_probe_time = Time.at(last_probe_score)
        zombie_score = RedisQueuedLocks::Resource.calc_zombie_score(zombie_ttl / 1_000.0)
        is_zombie = last_probe_score < zombie_score
        { zombie: is_zombie, last_probe_time:, last_probe_score: }
      end
    end
  end
end