Module: KicksLiveness
- Defined in:
- lib/kicks_liveness.rb,
lib/kicks_liveness/hooks.rb,
lib/kicks_liveness/monitor.rb,
lib/kicks_liveness/railtie.rb,
lib/kicks_liveness/version.rb,
lib/kicks_liveness/attempts.rb,
lib/kicks_liveness/registry.rb,
lib/kicks_liveness/heartbeat.rb,
lib/kicks_liveness/configuration.rb
Overview
Liveness probe for Kicks and Sneakers workers, backed by a tmpfs heartbeat.
The worker publishes a mark from inside its own process, checking its Bunny consumers in memory; the probe reads only the container generation and mark mtimes. No Rails, no call to the broker.
Defined Under Namespace
Modules: ContainerGeneration, GenerationGuard, Hooks, Registry Classes: Attempts, Configuration, Heartbeat, Monitor, Railtie
Constant Summary collapse
- VERSION =
Returns gem version.
'0.1.2'.freeze
Class Method Summary collapse
-
.config ⇒ Configuration
The process-wide configuration.
-
.configure {|config| ... } ⇒ Configuration
Yields the configuration for the application to adjust.
-
.install! ⇒ Module
Installs the two hooks the gem works through.
-
.start!(slot:, processes:, consumers:) ⇒ Thread?
private
Starts the monitor thread.
Class Method Details
.config ⇒ Configuration
Returns the process-wide configuration.
20 21 22 |
# File 'lib/kicks_liveness.rb', line 20 def config @config ||= Configuration.new end |
.configure {|config| ... } ⇒ Configuration
Yields the configuration for the application to adjust.
33 34 35 36 |
# File 'lib/kicks_liveness.rb', line 33 def configure yield(config) config end |
.install! ⇒ Module
Installs the two hooks the gem works through. Must run before the runner starts; in Rails a Railtie does it. Idempotent — prepending the same module twice is a no-op.
Two requires, not one: Sneakers::Worker is defined by lib/sneakers.rb,
while Sneakers::WorkerGroup comes only with sneakers/workergroup, which
ships with the runner and is absent in web processes. Relying on the
application having required sneakers itself is not safe: with
gem 'kicks', require: false the to_prepare hook runs earlier and
would fail on NameError.
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/kicks_liveness.rb', line 53 def install! reject_ambiguous_worker_gems! begin require 'sneakers' require 'sneakers/workergroup' rescue LoadError => e # The original message is kept: this rescue fires just as readily when # the worker gem is installed but something inside it fails to load — a # bunny or serverengine version that cannot be required, an extension # not built for the image. Reporting that as "the gem is missing" sends # the reader to check a Gemfile.lock that is perfectly fine. raise LoadError, 'kicks_liveness requires the kicks (>= 3.0) or sneakers (>= 2.11) gem ' \ "(#{e.})" end ::Sneakers::Worker.prepend(Hooks::Worker) ::Sneakers::WorkerGroup.prepend(Hooks::WorkerGroup) end |
.start!(slot:, processes:, consumers:) ⇒ Thread?
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.
Starts the monitor thread. Called from the WorkerGroup hook, already inside the fork.
81 82 83 84 85 |
# File 'lib/kicks_liveness.rb', line 81 def start!(slot:, processes:, consumers:) return unless config.enabled? Monitor.new(slot: slot, processes: processes, consumers: consumers, config: config).start! end |