Module: Datadog::Core::Utils::Forking

Overview

Helper methods for managing forking behavior

Defined Under Namespace

Modules: ClassExtensions

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.extended(base) ⇒ Object



10
11
12
13
14
15
16
# File 'lib/datadog/core/utils/forking.rb', line 10

def self.extended(base)
  # Explicitly update PID here because there's a case where
  # the code path that lazily updates the PID may not be exercised
  # until after a fork occurs, thus causing the event to be missed.
  # By eagerly setting this, we avoid this scenario.
  base.update_fork_pid!
end

.included(base) ⇒ Object



6
7
8
# File 'lib/datadog/core/utils/forking.rb', line 6

def self.included(base)
  base.prepend(ClassExtensions) if base.is_a?(Class)
end

Instance Method Details

#after_fork!Object



18
19
20
21
22
23
24
25
26
# File 'lib/datadog/core/utils/forking.rb', line 18

def after_fork!
  if forked?
    yield
    update_fork_pid!
    true
  else
    false
  end
end

#fork_pidObject



36
37
38
# File 'lib/datadog/core/utils/forking.rb', line 36

def fork_pid
  @fork_pid ||= Process.pid
end

#forked?Boolean

Returns:

  • (Boolean)


28
29
30
# File 'lib/datadog/core/utils/forking.rb', line 28

def forked?
  Process.pid != fork_pid
end

#update_fork_pid!Object



32
33
34
# File 'lib/datadog/core/utils/forking.rb', line 32

def update_fork_pid!
  @fork_pid = Process.pid
end