Class: Wurk::Batch::Buffer

Inherits:
Struct
  • Object
show all
Defined in:
lib/wurk/batch/buffer.rb

Overview

Accumulates batched payloads inside an autoflush ‘Batch#jobs` block so the whole block flushes in one pipeline (`autoflush == true`) or every N jobs (`autoflush == Integer`). Client#raw_push fills it; Batch#jobs drains the remainder at block exit.

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#payloadsObject

Returns the value of attribute payloads

Returns:

  • (Object)

    the current value of payloads



9
10
11
# File 'lib/wurk/batch/buffer.rb', line 9

def payloads
  @payloads
end

#thresholdObject

Returns the value of attribute threshold

Returns:

  • (Object)

    the current value of threshold



9
10
11
# File 'lib/wurk/batch/buffer.rb', line 9

def threshold
  @threshold
end

Instance Method Details

#add(items) ⇒ Object



10
11
12
13
# File 'lib/wurk/batch/buffer.rb', line 10

def add(items)
  payloads.concat(items)
  self
end

#drainObject



19
20
21
22
23
# File 'lib/wurk/batch/buffer.rb', line 19

def drain
  out = payloads.dup
  payloads.clear
  out
end

#ready?Boolean

Returns:

  • (Boolean)


15
16
17
# File 'lib/wurk/batch/buffer.rb', line 15

def ready?
  !threshold.nil? && payloads.length >= threshold
end