Class: RedisQueuedLocks::Swarm::ProbeHosts Private

Inherits:
SwarmElement::Threaded show all
Defined in:
lib/redis_queued_locks/swarm/probe_hosts.rb

Overview

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

Since:

  • 1.9.0

Constant Summary

Constants included from Utilities

Utilities::RACTOR_LIVENESS_PATTERN, Utilities::RACTOR_STATUS_PATTERN, Utilities::RUBY_OVER_4

Instance Attribute Summary

Attributes inherited from SwarmElement::Threaded

#main_loop, #rql_client, #swarm_element, #swarm_element_commands, #swarm_element_results, #sync

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from SwarmElement::Threaded

#initialize, #reswarm_if_dead!, #status, #try_kill!, #try_swarm!

Methods included from Utilities

clock_gettime, ractor_alive?, ractor_status, ruby_over_4?, run_non_critical, thread_state

Constructor Details

This class inherits a constructor from RedisQueuedLocks::Swarm::SwarmElement::Threaded

Class Method Details

.probe_hosts(redis_client, uniq_identity) ⇒ ::Hash

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 a list of living hosts as a element command result. Result example: { ok: , result: { host_id1 => score1 , host_id2 => score2 , etc... } }

Parameters:

  • redis_client (RedisClient)
  • uniq_identity (String)

Returns:

  • (::Hash)

Since:

  • 1.9.0



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/redis_queued_locks/swarm/probe_hosts.rb', line 23

def probe_hosts(redis_client, uniq_identity)
  possible_hosts = RedisQueuedLocks::Resource.possible_host_identifiers(uniq_identity)
  probed_hosts = {} #: Hash[String,Float]

  redis_client.with do |rconn|
    possible_hosts.each do |host_id|
      rconn.call(
        'HSET',
        RedisQueuedLocks::Resource::SWARM_KEY,
        host_id,
        probe_score = Time.now.to_f
      )
      probed_hosts[host_id] = probe_score
    end
  end

  { ok: true, result: probed_hosts }
end

Instance Method Details

#enabled? ⇒ Boolean

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:

  • (Boolean)

Since:

  • 1.9.0



47
48
49
# File 'lib/redis_queued_locks/swarm/probe_hosts.rb', line 47

def enabled?
  rql_client.config['swarm.probe_hosts.enabled_for_swarm']
end

#spawn_main_loop! ⇒ Thread

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:

  • (Thread)

Since:

  • 1.9.0



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/redis_queued_locks/swarm/probe_hosts.rb', line 55

def spawn_main_loop!
  Thread.new do
    redis_client = RedisQueuedLocks::Swarm::RedisClientBuilder.build(
      pooled: rql_client.config['swarm.probe_hosts.redis_config.pooled'],
      sentinel: rql_client.config['swarm.probe_hosts.redis_config.sentinel'],
      config: rql_client.config['swarm.probe_hosts.redis_config.config'],
      pool_config: rql_client.config['swarm.probe_hosts.redis_config.pool_config']
    )

    loop do
      RedisQueuedLocks::Swarm::ProbeHosts.probe_hosts(redis_client, rql_client.uniq_identity)
      sleep(rql_client.config['swarm.probe_hosts.probe_period'])
    end
  end
end