Module: Datadog::Core::Workers::Polling

Included in:
Telemetry::Worker, RuntimeMetrics, Profiling::Scheduler, Tracing::Workers::AsyncTraceWriter
Defined in:
lib/datadog/core/workers/polling.rb

Overview

Adds polling (async looping) behavior to workers

Defined Under Namespace

Modules: PrependedMethods

Constant Summary collapse

DEFAULT_SHUTDOWN_TIMEOUT =
1

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



13
14
15
16
17
# File 'lib/datadog/core/workers/polling.rb', line 13

def self.included(base)
  base.include(Workers::IntervalLoop)
  base.include(Workers::Async::Thread)
  base.prepend(PrependedMethods)
end

Instance Method Details

#enabled=(value) ⇒ Object

Allow worker to be started



52
53
54
55
# File 'lib/datadog/core/workers/polling.rb', line 52

def enabled=(value)
  # Coerce to boolean
  @enabled = (value == true)
end

#enabled?Boolean

Returns:

  • (Boolean)


45
46
47
48
49
# File 'lib/datadog/core/workers/polling.rb', line 45

def enabled?
  return true unless instance_variable_defined?(:@enabled)

  @enabled
end

#stop(force_stop = false, timeout = DEFAULT_SHUTDOWN_TIMEOUT) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/datadog/core/workers/polling.rb', line 26

def stop(force_stop = false, timeout = DEFAULT_SHUTDOWN_TIMEOUT)
  if running?
    # Attempt graceful stop and wait
    stop_loop
    graceful = join(timeout)

    if !graceful && force_stop
      Datadog.logger.debug do
        "Timeout while waiting for worker to finish gracefully, forcing termination for: #{self}"
      end
      terminate
    else
      graceful
    end
  else
    false
  end
end