Class: RedisQueuedLocks::Swarm::Supervisor Private

Inherits:
Object
  • Object
show all
Includes:
Utilities
Defined in:
lib/redis_queued_locks/swarm/supervisor.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 collapse

Instance Method Summary collapse

Methods included from Utilities

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

Constructor Details

#initialize(rql_client) ⇒ void

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.

Since:

  • 1.9.0



31
32
33
34
35
# File 'lib/redis_queued_locks/swarm/supervisor.rb', line 31

def initialize(rql_client)
  @rql_client = rql_client
  @visor = nil
  @observable = nil
end

Instance Attribute Details

#observable ⇒ Proc, NilClass (readonly)

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:

  • (Proc, NilClass)

Since:

  • 1.9.0



25
26
27
# File 'lib/redis_queued_locks/swarm/supervisor.rb', line 25

def observable
  @observable
end

#rql_client ⇒ RedisQueuedLocks::Client (readonly)

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:

Since:

  • 1.9.0



13
14
15
# File 'lib/redis_queued_locks/swarm/supervisor.rb', line 13

def rql_client
  @rql_client
end

#visor ⇒ Thread, NilClass (readonly)

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, NilClass)

Since:

  • 1.9.0



19
20
21
# File 'lib/redis_queued_locks/swarm/supervisor.rb', line 19

def visor
  @visor
end

Instance Method Details

#observe!(&observable) ⇒ void

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.

This method returns an undefined value.

Parameters:

  • observable (Block)

Since:

  • 1.9.0



42
43
44
45
46
47
48
49
50
51
52
# File 'lib/redis_queued_locks/swarm/supervisor.rb', line 42

def observe!(&observable)
  @observable = observable
  @visor = Thread.new do
    loop do
      yield rescue nil # TODO: (CHECK): may be we need to process exceptions here
      sleep(rql_client.config['swarm.supervisor.liveness_probing_period'])
    end
  end
  # NOTE: need to give a timespot to initialize a visor thread;
  sleep(0.1)
end

#running? ⇒ 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



58
59
60
61
62
63
64
# File 'lib/redis_queued_locks/swarm/supervisor.rb', line 58

def running?
  # NOTE:
  #   steep can not understand that visor.alive? is invoked on
  #   `::Thread` here (not on `::Thread | nil` after the `nil`-check);
  #   so we need to ignore this check temporary and wait the best future :)
  visor != nil && visor.alive? # steep:ignore
end

#status ⇒ Hash<Symbol|Hash<Symbol,String|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:

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

Since:

  • 1.9.0



84
85
86
87
88
89
90
91
92
93
94
95
# File 'lib/redis_queued_locks/swarm/supervisor.rb', line 84

def status
  # NOTE:
  #   steep can not understand that thread_state(visor) is invoked on
  #   `::Thread` here (not on `::Thread | nil` after the `nil`-check);
  #   so we need to ignore this check temporary and wait the best future :)

  {
    running: running?,
    state: (visor == nil) ? 'non_initialized' : thread_state(visor), # steep:ignore
    observable: (observable == nil) ? 'non_initialized' : 'initialized'
  }
end

#stop! ⇒ void

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.

This method returns an undefined value.

Since:

  • 1.9.0



70
71
72
73
74
75
76
77
78
# File 'lib/redis_queued_locks/swarm/supervisor.rb', line 70

def stop!
  # NOTE:
  #   steep can not understand that visor.kill is invoked on
  #   `::Thread` here (not on `::Thread | nil` after the `nil`-check);
  #   so we need to ignore this check temporary and wait the best future :)
  visor.kill if running? # steep:ignore
  @visor = nil
  @observable = nil
end