Module: KicksLiveness::Hooks::WorkerGroup Private

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

Prepended to Sneakers::WorkerGroup.

ServerEngine::Server#create_worker calls w.extend(worker_module), so WorkerGroup lands in the singleton class of the instance rather than being included in a class. A prepend to the module still sits ahead of it in that lookup chain; worker_id and config come from ServerEngine::Worker.

See Also:

API:

  • private

Instance Method Summary collapse

Instance Method Details

#after_forkvoid

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.

This method returns an undefined value.

Starts the monitor from after_fork rather than from run.

Sneakers::WorkerGroup#run calls after_fork as its very first statement and only afterwards resolves worker_classes, so this is the earliest point in the fork at which the application's own after_fork hook has already run. That ordering matters because resolving the expected consumer count may run application code: under sneakers:active_job the set is a callable registry, and the standard use of after_fork is to re-establish the connections a fork inherited. Resolving it first would run that code against a fork that is not ready.

Wrapped in a rescue: instrumentation has no right to prevent a worker from starting, so the worst outcome is a missing mark and a pod restart rather than a pod that stays up with silent queues.

API:

  • private



53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/kicks_liveness/hooks.rb', line 53

def after_fork
  super

  begin
    KicksLiveness.start!(
      slot: worker_id,
      processes: config[:workers] || 1,
      consumers: kicks_liveness_expected_consumers
    )
  rescue StandardError => e
    report_start_failure(e)
  end
end

#stopvoid

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.

This method returns an undefined value.

Marks the shutdown as deliberate before the workers unsubscribe.

Sneakers::WorkerGroup#stop calls stop on each worker, and Sneakers::Worker#stop waits for the thread pool to drain, which takes as long as the longest in-flight job. The registry empties at the start of that, so without this flag the monitor would report a fault on every ordinary deploy.

API:

  • private



76
77
78
79
# File 'lib/kicks_liveness/hooks.rb', line 76

def stop
  Registry.stopping!
  super
end