Class: Polipus::QueueOverflow::Manager
- Inherits:
-
Object
- Object
- Polipus::QueueOverflow::Manager
- Defined in:
- lib/polipus/queue_overflow/manager.rb
Instance Attribute Summary collapse
-
#polipus ⇒ Object
readonly
Returns the value of attribute polipus.
-
#url_filter(&block) ⇒ Object
Returns the value of attribute url_filter.
Instance Method Summary collapse
-
#initialize(polipus, main_q, item_limit) ⇒ Manager
constructor
A new instance of Manager.
- #perform ⇒ Object
Constructor Details
#initialize(polipus, main_q, item_limit) ⇒ Manager
Returns a new instance of Manager.
7 8 9 10 11 12 13 |
# File 'lib/polipus/queue_overflow/manager.rb', line 7 def initialize(polipus, main_q, item_limit) @polipus = polipus @main_q = main_q @adapter = @polipus.queue_overflow_adapter @item_limit = item_limit @redis = @polipus.redis end |
Instance Attribute Details
#polipus ⇒ Object (readonly)
Returns the value of attribute polipus.
6 7 8 |
# File 'lib/polipus/queue_overflow/manager.rb', line 6 def polipus @polipus end |
#url_filter(&block) ⇒ Object
Returns the value of attribute url_filter.
5 6 7 |
# File 'lib/polipus/queue_overflow/manager.rb', line 5 def url_filter @url_filter end |
Instance Method Details
#perform ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/polipus/queue_overflow/manager.rb', line 19 def perform removed = 0 restored = 0 main_q_size = @main_q.size if main_q_size > @item_limit @polipus.logger.info { "Overflow Manager: Going to offload items from redis: ~#{main_q_size - @item_limit}" } removed = rotate(@main_q, @adapter) { @main_q.size > @item_limit } elsif main_q_size < @item_limit && !@adapter.empty? @polipus.logger.info { "Overflow Manager: Going to restore items into redis: ~#{@item_limit - main_q_size}" } restored = rotate(@adapter, @main_q) { @main_q.size <= @item_limit } end [removed, restored] end |