Module: RedisQueuedLocks::Utilities Private

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.0.0

Version:

  • 1.16.0

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_s methods. 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 status part of the inspect method and use it for our logic. Current regexp object provides the pattern for this.

Returns:

  • (Regexp)

Since:

  • 1.9.0

/\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"

Returns:

  • (Regexp)

Since:

  • 1.9.0

/\A.*?\s(?<status>\w+)>\z/i
RUBY_OVER_4 =

Returns:

  • (Boolean)

Since:

  • ?.?.?

Gem::Version.new(RUBY_VERSION) >= Gem::Version.new('4.0.0')

Class Method Summary collapse

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.

Returns:

  • (Integer)

Since:

  • 1.14.0



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.

Parameters:

  • ractor (Ractor)

Returns:

  • (Boolean)

Since:

  • 1.9.0



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"

Parameters:

  • ractor (Ractor)

Returns:

  • (String)

Since:

  • 1.9.0



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

Returns:

  • (Boolean)

Since:

  • 1.16.0



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.

Yields:

Yield Returns:

  • (Any)

Returns:

  • (Any)

Since:

  • 1.0.0



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.

Parameters:

  • thread (Thread)

Returns:

  • (String)

Since:

  • 1.9.0



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