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.
Class Method Summary collapse
-
.add(worker) ⇒ Array
private
Records a worker as subscribed.
-
.healthy?(expected) ⇒ Boolean
private
Whether this process is consuming everything it is supposed to consume.
-
.remove(worker) ⇒ Sneakers::Worker?
private
Drops a worker from the registry, on shutdown.
-
.size ⇒ Integer
private
How many workers are currently registered.
-
.stopping! ⇒ true
private
Records that this process is shutting down on purpose.
-
.stopping? ⇒ Boolean
private
Whether shutdown has begun.
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.
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.
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.
35 36 37 |
# File 'lib/kicks_liveness/registry.rb', line 35 def remove(worker) @mutex.synchronize { @workers.delete(worker) } end |
.size ⇒ 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 how many workers are currently registered.
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.
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.
56 57 58 |
# File 'lib/kicks_liveness/registry.rb', line 56 def stopping? @stopping end |