Class: RedisQueuedLocks::Swarm::SwarmElement::Isolated Private
- Inherits:
-
Object
- Object
- RedisQueuedLocks::Swarm::SwarmElement::Isolated
- Includes:
- Utilities
- Defined in:
- lib/redis_queued_locks/swarm/swarm_element/isolated.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.
rubocop:disable Metrics/ClassLength
Direct Known Subclasses
Constant Summary
Constants included from Utilities
Utilities::RACTOR_LIVENESS_PATTERN, Utilities::RACTOR_STATUS_PATTERN, Utilities::RUBY_OVER_4
Instance Attribute Summary collapse
- #rql_client ⇒ RedisQueuedLocks::Client readonly private
- #swarm_element ⇒ Ractor, NilClass readonly private
- #sync ⇒ RedisQueuedLocks::Utilities::Lock readonly private
Class Method Summary collapse
-
.swarm_loop(&main_loop_spawner) ⇒ void
private
rubocop:disable Layout/ClassStructure, Lint/IneffectiveAccessModifier, Metrics/MethodLength.
Instance Method Summary collapse
- #enabled? ⇒ Boolean private
- #initialize(rql_client) ⇒ void constructor private
- #reswarm_if_dead! ⇒ void private
-
#status ⇒ Hash<Symbol,Boolean|Hash<Symbol,String|Boolean>>
private
Format: { enabled:
, ractor: { running: , state: , }, main_loop: { running: , state: } }. - #try_kill! ⇒ void private
- #try_swarm! ⇒ void private
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.
33 34 35 36 37 |
# File 'lib/redis_queued_locks/swarm/swarm_element/isolated.rb', line 33 def initialize(rql_client) @rql_client = rql_client @swarm_element = nil @sync = RedisQueuedLocks::Utilities::Lock.new end |
Instance Attribute Details
#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.
14 15 16 |
# File 'lib/redis_queued_locks/swarm/swarm_element/isolated.rb', line 14 def rql_client @rql_client end |
#swarm_element ⇒ Ractor, 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.
20 21 22 |
# File 'lib/redis_queued_locks/swarm/swarm_element/isolated.rb', line 20 def swarm_element @swarm_element end |
#sync ⇒ RedisQueuedLocks::Utilities::Lock (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.
26 27 28 |
# File 'lib/redis_queued_locks/swarm/swarm_element/isolated.rb', line 26 def sync @sync end |
Class Method Details
.swarm_loop(&main_loop_spawner) ⇒ 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.
rubocop:disable Layout/ClassStructure, Lint/IneffectiveAccessModifier, Metrics/MethodLength
158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 |
# File 'lib/redis_queued_locks/swarm/swarm_element/isolated.rb', line 158 def self.swarm_loop(&main_loop_spawner) # NOTE: # This self.-related part of code is placed in the middle of class in order # to provide better code readability (it is placed next to the method inside # wich it should be called (see #swarm!)). That's why some rubocop cops are disabled. # @type var main_loop: Thread? main_loop = nil loop do command = Ractor.receive case command when :status main_loop_alive = main_loop != nil && main_loop.alive? # steep:ignore main_loop_state = if main_loop == nil 'non_initialized' else # @type var main_loop: Thread RedisQueuedLocks::Utilities.thread_state(main_loop) end # NOTE: (will be reworked with Ractor::Port in the next RQL release (~1.17)) Ractor.yield({ # steep:ignore main_loop: { alive: main_loop_alive, state: main_loop_state } }) when :is_active Ractor.yield(main_loop != nil && main_loop.alive?) # steep:ignore when :start main_loop.kill if main_loop != nil # steep:ignore main_loop = yield # REFERENCE: `main_loop_spawner.call` when :stop main_loop.kill if main_loop != nil # steep:ignore when :kill main_loop.kill if main_loop != nil # steep:ignore exit end end 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.
84 85 86 |
# File 'lib/redis_queued_locks/swarm/swarm_element/isolated.rb', line 84 def enabled? # steep:ignore # NOTE: provide an <is enabled> logic here by analyzing the redis queued locks config. end |
#reswarm_if_dead! ⇒ 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.
57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/redis_queued_locks/swarm/swarm_element/isolated.rb', line 57 def reswarm_if_dead! return unless enabled? sync.synchronize do if swarmed__stopped? swarm_loop__start elsif swarmed__dead? || idle? swarm! swarm_loop__start end end end |
#status ⇒ Hash<Symbol,Boolean|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 Format:
{
enabled:
103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 |
# File 'lib/redis_queued_locks/swarm/swarm_element/isolated.rb', line 103 def status sync.synchronize do ractor_running = swarmed__alive? ractor_state = swarmed? ? ractor_status(swarm_element) : 'non_initialized' # steep:ignore begin main_loop_running = swarmed__running? # steep:ignore:start main_loop_state = main_loop_running ? swarm_loop__status[:main_loop][:state] : 'non_initialized' # steep:ignore:end rescue Ractor::ClosedError # NOTE: it can happend when you running RedisQueuedLocks::Swarm#deswarm! main_loop_running = false main_loop_state = 'non_initialized' end { enabled: enabled?, ractor: { running: ractor_running, state: ractor_state }, main_loop: { running: main_loop_running, state: main_loop_state } } end end |
#try_kill! ⇒ 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.
74 75 76 77 78 |
# File 'lib/redis_queued_locks/swarm/swarm_element/isolated.rb', line 74 def try_kill! sync.synchronize do swarm_loop__kill end end |
#try_swarm! ⇒ 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.
43 44 45 46 47 48 49 50 51 |
# File 'lib/redis_queued_locks/swarm/swarm_element/isolated.rb', line 43 def try_swarm! return unless enabled? sync.synchronize do swarm_loop__kill swarm! swarm_loop__start end end |