Module: Datadog::Workers::Polling

Defined in:
lib/ddtrace/workers/polling.rb

Overview

Adds polling (async looping) behavior to workers

Defined Under Namespace

Modules: PrependedMethods

Constant Summary collapse

SHUTDOWN_TIMEOUT =
1

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



10
11
12
13
14
# File 'lib/ddtrace/workers/polling.rb', line 10

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

Instance Method Details

#enabled=(value) ⇒ Object

Allow worker to be started



42
43
44
45
# File 'lib/ddtrace/workers/polling.rb', line 42

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

#enabled?Boolean

Returns:

  • (Boolean)


36
37
38
39
# File 'lib/ddtrace/workers/polling.rb', line 36

def enabled?
  @enabled = true unless instance_variable_defined?(:@enabled)
  @enabled
end

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



23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/ddtrace/workers/polling.rb', line 23

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

    # If timeout and force stop...
    !graceful && force_stop ? terminate : graceful
  else
    false
  end
end