Class: Wurk::Batch::Buffer
- Inherits:
-
Struct
- Object
- Struct
- Wurk::Batch::Buffer
- 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
-
#payloads ⇒ Object
Returns the value of attribute payloads.
-
#threshold ⇒ Object
Returns the value of attribute threshold.
Instance Method Summary collapse
Instance Attribute Details
#payloads ⇒ Object
Returns the value of attribute payloads
9 10 11 |
# File 'lib/wurk/batch/buffer.rb', line 9 def payloads @payloads end |
#threshold ⇒ Object
Returns the value of attribute 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 |
#drain ⇒ Object
19 20 21 22 23 |
# File 'lib/wurk/batch/buffer.rb', line 19 def drain out = payloads.dup payloads.clear out end |
#ready? ⇒ Boolean
15 16 17 |
# File 'lib/wurk/batch/buffer.rb', line 15 def ready? !threshold.nil? && payloads.length >= threshold end |