Module: RedisQueuedLocks::Utilities Private
- Included in:
- Acquirer::AcquireLock, Acquirer::ReleaseAllLocks, Acquirer::ReleaseLock, Acquirer::ReleaseLocksOf, Swarm::Supervisor, Swarm::SwarmElement::Isolated, Swarm::SwarmElement::Threaded
- Defined in:
- lib/redis_queued_locks/utilities.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.
Defined Under Namespace
Classes: Lock
Constant Summary collapse
- RACTOR_LIVENESS_PATTERN =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
Ractor class has no methods for Ractor object status identification. The only one approach (without C/FFI extending) to give the status is to check the status from the
#inspect/#to_smethods. String representation has the following format:Format: "#<Ractor:##{id}#{name ? ' '+name : ''}#{loc ? " " + loc : ''} #{status}>" Example: #<Ractor:#2 (irb):2 terminated>So we need to parse the
statuspart of the inspect method and use it for our logic. Current regexp object provides the pattern for this. /\A.*?(created|running|blocking).*?\z/i- RACTOR_STATUS_PATTERN =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
Ractor status as a string extracted from the object string representation. This way is used cuz the ractor class has no any detailed status extraction API. Possible statuses (at the moment of [email protected]):
- "created" - "blocking" - "running" - "terminated" /\A.*?\s(?<status>\w+)>\z/i- RUBY_OVER_4 =
Gem::Version.new(RUBY_VERSION) >= Gem::Version.new('4.0.0')
Class Method Summary collapse
- .clock_gettime ⇒ Integer private
- .ractor_alive?(ractor) ⇒ Boolean private
-
.ractor_status(ractor) ⇒ String
private
Possible statuses (at the moment of [email protected]): - "created" - "blocking" - "running" - "terminated".
- .ruby_over_4? ⇒ Boolean
- .run_non_critical { ... } ⇒ Any private
-
.thread_state(thread) ⇒ String
private
Returns the status of the passed thread object.
Class Method Details
.clock_gettime ⇒ Integer
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.
59 60 61 |
# File 'lib/redis_queued_locks/utilities.rb', line 59 def clock_gettime ::Process.clock_gettime(::Process::CLOCK_MONOTONIC, :microsecond) end |
.ractor_alive?(ractor) ⇒ 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.
83 84 85 |
# File 'lib/redis_queued_locks/utilities.rb', line 83 def ractor_alive?(ractor) ractor.to_s.match?(RACTOR_LIVENESS_PATTERN) end |
.ractor_status(ractor) ⇒ 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.
Possible statuses (at the moment of [email protected]):
- "created"
- "blocking"
- "running"
- "terminated"
74 75 76 |
# File 'lib/redis_queued_locks/utilities.rb', line 74 def ractor_status(ractor) ractor.to_s.match(RACTOR_STATUS_PATTERN)[:status] # steep:ignore end |
.ruby_over_4? ⇒ Boolean
112 113 114 |
# File 'lib/redis_queued_locks/utilities.rb', line 112 def ruby_over_4? RUBY_OVER_4 end |
.run_non_critical { ... } ⇒ Any
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.
51 52 53 |
# File 'lib/redis_queued_locks/utilities.rb', line 51 def run_non_critical(&block) yield rescue nil end |
.thread_state(thread) ⇒ 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.
Returns the status of the passed thread object. Possible statuses:
- "run" (thread is executing);
- "sleep" (thread is sleeping or waiting on I/O);
- "aborting" (thread is aborting)
- "dead" (thread is terminated normally);
- "failed" (thread is terminated with an exception);
See Thread#status official documentation.
101 102 103 104 105 106 |
# File 'lib/redis_queued_locks/utilities.rb', line 101 def thread_state(thread) status = thread.status return 'dead' if status == false return 'failed' if status == nil status #: String end |