Sha256: cc300fdbf4882f4a6f52ccd857c69afa77ebc55ba7cb3bb51e6e499e1d523e1c

Contents?: true

Size: 849 Bytes

Versions: 35

Compression:

Stored size: 849 Bytes

Contents

# frozen_string_literal: true

module Datadog
  module Core
    module Workers
      # Adds queue behavior to workers, with a buffer
      # to which items can be queued then dequeued.
      module Queue
        def self.included(base)
          base.prepend(PrependedMethods)
        end

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

        def buffer
          @buffer ||= []
        end

        def enqueue(*args)
          buffer.push(args)
        end

        def dequeue
          buffer.shift
        end

        # Are there more items to be processed next?
        def work_pending?
          !buffer.empty?
        end

        protected

        attr_writer \
          :buffer
      end
    end
  end
end

Version data entries

35 entries across 35 versions & 2 rubygems

Version Path
datadog-2.9.0 lib/datadog/core/workers/queue.rb
datadog-2.8.0 lib/datadog/core/workers/queue.rb
datadog-2.7.1 lib/datadog/core/workers/queue.rb
datadog-2.7.0 lib/datadog/core/workers/queue.rb
datadog-2.6.0 lib/datadog/core/workers/queue.rb
datadog-2.5.0 lib/datadog/core/workers/queue.rb
datadog-2.4.0 lib/datadog/core/workers/queue.rb
datadog-2.3.0 lib/datadog/core/workers/queue.rb
datadog-2.2.0 lib/datadog/core/workers/queue.rb
ddtrace-1.23.3 lib/datadog/core/workers/queue.rb
ddtrace-1.23.2 lib/datadog/core/workers/queue.rb
datadog-2.1.0 lib/datadog/core/workers/queue.rb
datadog-2.0.0 lib/datadog/core/workers/queue.rb
ddtrace-1.23.1 lib/datadog/core/workers/queue.rb
datadog-2.0.0.beta2 lib/datadog/core/workers/queue.rb
ddtrace-1.22.0 lib/datadog/core/workers/queue.rb
datadog-2.0.0.beta1 lib/datadog/core/workers/queue.rb
ddtrace-1.21.1 lib/datadog/core/workers/queue.rb
ddtrace-1.21.0 lib/datadog/core/workers/queue.rb
ddtrace-1.20.0 lib/datadog/core/workers/queue.rb