Class: S3DataPacker::Queue
- Inherits:
-
Object
- Object
- S3DataPacker::Queue
- Defined in:
- lib/s3_data_packer/queue.rb
Instance Attribute Summary collapse
-
#items ⇒ Object
readonly
Returns the value of attribute items.
-
#total_items ⇒ Object
readonly
Returns the value of attribute total_items.
Instance Method Summary collapse
- #add!(item) ⇒ Object
- #fetch! ⇒ Object
-
#initialize(opts = {}) ⇒ Queue
constructor
A new instance of Queue.
- #max_items ⇒ Object
- #reset! ⇒ Object
- #size ⇒ Object
- #wait_time ⇒ Object
Constructor Details
#initialize(opts = {}) ⇒ Queue
Returns a new instance of Queue.
5 6 7 8 9 |
# File 'lib/s3_data_packer/queue.rb', line 5 def initialize opts = {} @max_items = opts[:max_items] @wait_time = opts[:wait_time] @total_items = 0 end |
Instance Attribute Details
#items ⇒ Object (readonly)
Returns the value of attribute items.
3 4 5 |
# File 'lib/s3_data_packer/queue.rb', line 3 def items @items end |
#total_items ⇒ Object (readonly)
Returns the value of attribute total_items.
3 4 5 |
# File 'lib/s3_data_packer/queue.rb', line 3 def total_items @total_items end |
Instance Method Details
#add!(item) ⇒ Object
23 24 25 26 27 28 29 30 31 |
# File 'lib/s3_data_packer/queue.rb', line 23 def add!(item) items << item @total_items += 1 if size >= max_items S3DataPacker.logger.info "Queue full, pausing" sleep(wait_time) S3DataPacker.logger.info "Resuming queue" end end |
#fetch! ⇒ Object
33 34 35 |
# File 'lib/s3_data_packer/queue.rb', line 33 def fetch! items.shift end |
#max_items ⇒ Object
11 12 13 |
# File 'lib/s3_data_packer/queue.rb', line 11 def max_items @max_items ||= S3DataPacker.config.max_queue_size end |
#reset! ⇒ Object
41 42 43 44 |
# File 'lib/s3_data_packer/queue.rb', line 41 def reset! @items = [] @total_items = 0 end |
#size ⇒ Object
37 38 39 |
# File 'lib/s3_data_packer/queue.rb', line 37 def size items.size end |
#wait_time ⇒ Object
15 16 17 |
# File 'lib/s3_data_packer/queue.rb', line 15 def wait_time @wait_time ||= S3DataPacker.config.max_queue_wait end |