Module: KicksLiveness::Registry Private

Defined in:
lib/kicks_liveness/registry.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.

Registry of the workers that have subscribed in the current process, and the health predicate computed over them.

The predicate reads only in-process state: no network calls, no disk access.

See Also:

API:

  • private

Class Method Summary collapse

Class Method Details

.add(worker) ⇒ Array

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.

Records a worker as subscribed.

Registering the same object twice would break the size comparison in healthy? and leave the process permanently unhealthy, so identity is checked first. equal? rather than == on purpose: this is a registry of objects, and a worker class is free to define equality however it likes.

Parameters:

Returns:

  • the registry

API:

  • private



25
26
27
28
29
30
# File 'lib/kicks_liveness/registry.rb', line 25

def add(worker)
  @mutex.synchronize do
    @workers << worker unless @workers.any? { |registered| registered.equal?(worker) }
    @workers
  end
end

.healthy?(expected) ⇒ 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.

Whether this process is consuming everything it is supposed to consume.

The registry size is compared against expected rather than only checking the workers that did register: four healthy workers out of five look fine one object at a time.

Parameters:

  • how many workers must have subscribed in this process

Returns:

API:

  • private



68
69
70
71
72
73
# File 'lib/kicks_liveness/registry.rb', line 68

def healthy?(expected)
  workers = @mutex.synchronize { @workers.dup }
  return false unless expected.positive? && workers.size == expected

  workers.all? { |worker| alive?(worker) }
end

.remove(worker) ⇒ Sneakers::Worker?

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.

Drops a worker from the registry, on shutdown.

Parameters:

Returns:

API:

  • private



35
36
37
# File 'lib/kicks_liveness/registry.rb', line 35

def remove(worker)
  @mutex.synchronize { @workers.delete(worker) }
end

.sizeInteger

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 how many workers are currently registered.

Returns:

  • how many workers are currently registered

API:

  • private



40
41
42
# File 'lib/kicks_liveness/registry.rb', line 40

def size
  @mutex.synchronize { @workers.size }
end

.stopping!true

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.

Records that this process is shutting down on purpose.

Without it a graceful shutdown is indistinguishable from a failure: the registry empties as each worker unsubscribes, so the monitor would see an incomplete set and report a genuine fault on every deploy.

Returns:

API:

  • private



51
52
53
# File 'lib/kicks_liveness/registry.rb', line 51

def stopping!
  @stopping = true
end

.stopping?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 whether shutdown has begun.

Returns:

  • whether shutdown has begun

API:

  • private



56
57
58
# File 'lib/kicks_liveness/registry.rb', line 56

def stopping?
  @stopping
end