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



14
15
16
17
18
19
20
# File 'lib/datadog/core/utils/forking.rb', line 14

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



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

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

Instance Method Details

#after_fork!Object



22
23
24
25
26
27
28
29
30
# File 'lib/datadog/core/utils/forking.rb', line 22

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

#fork_pidObject



40
41
42
# File 'lib/datadog/core/utils/forking.rb', line 40

def fork_pid
  @fork_pid ||= Process.pid
end

#forked?Boolean

Returns:

  • (Boolean)


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

def forked?
  Process.pid != fork_pid
end

#update_fork_pid!Object



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

def update_fork_pid!
  @fork_pid = Process.pid
end