Sha256: 0eb599824beff0f1d4a0c5d36051fcaaafe4c38c102234947868d1c206ccd3a3

Contents?: true

Size: 1.1 KB

Versions: 7

Compression:

Stored size: 1.1 KB

Contents

require 'ddtrace/workers/async'
require 'ddtrace/workers/loop'

module Datadog
  module Workers
    # Adds polling (async looping) behavior to workers
    module Polling
      SHUTDOWN_TIMEOUT = 1

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

      # Methods that must be prepended
      module PrependedMethods
        def perform(*args)
          super if enabled?
        end
      end

      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

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

      # Allow worker to be started
      def enabled=(value)
        # Coerce to boolean
        @enabled = (value == true)
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 2 rubygems

Version Path
ddtrace-0.45.0 lib/ddtrace/workers/polling.rb
ddtrace-0.44.0 lib/ddtrace/workers/polling.rb
ddtrace-0.43.0 lib/ddtrace/workers/polling.rb
ddtrace-0.42.0 lib/ddtrace/workers/polling.rb
ddtrace-0.41.0 lib/ddtrace/workers/polling.rb
ls-trace-0.2.0 lib/ddtrace/workers/polling.rb
ddtrace-0.40.0 lib/ddtrace/workers/polling.rb