module Datadog::Workers::Polling

Adds polling (async looping) behavior to workers

Constants

SHUTDOWN_TIMEOUT

Public Class Methods

included(base) click to toggle source
# File lib/ddtrace/workers/polling.rb, line 11
def self.included(base)
  base.include(Workers::IntervalLoop)
  base.include(Workers::Async::Thread)
  base.prepend(PrependedMethods)
end

Public Instance Methods

enabled=(value) click to toggle source

Allow worker to be started

# File lib/ddtrace/workers/polling.rb, line 50
def enabled=(value)
  # Coerce to boolean
  @enabled = (value == true)
end
enabled?() click to toggle source
# File lib/ddtrace/workers/polling.rb, line 43
def enabled?
  return true unless instance_variable_defined?(:@enabled)

  @enabled
end
stop(force_stop = false, timeout = SHUTDOWN_TIMEOUT) click to toggle source
# File lib/ddtrace/workers/polling.rb, line 24
def stop(force_stop = false, timeout = 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