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.

See Also:

Defined Under Namespace

Modules: ContainerGeneration, GenerationGuard, Hooks, Registry Classes: Attempts, Configuration, Heartbeat, Monitor, Railtie

Constant Summary collapse

VERSION =

Returns gem version.

Returns:

  • (String)

    gem version

'0.1.2'.freeze

Class Method Summary collapse

Class Method Details

.configConfiguration

Returns the process-wide configuration.

Returns:



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.

Examples:

KicksLiveness.configure do |config|
  config.enabled = !Rails.env.local?
end

Yield Parameters:

Returns:



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.

Returns:

  • (Module)

Raises:

  • (LoadError)

    if neither worker gem is available, or if both kicks and sneakers are activated

See Also:



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.message})"
  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.

Parameters:

  • slot (Integer)

    supervisor slot of this fork

  • processes (Integer)

    how many forks the probe must wait for

  • consumers (Integer)

    how many workers must subscribe here

Returns:

  • (Thread, nil)

    nil when disabled by configuration



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