Class: Dynflow::Watchers::MemoryConsumptionWatcher
- Inherits:
-
Object
- Object
- Dynflow::Watchers::MemoryConsumptionWatcher
- Defined in:
- lib/dynflow/watchers/memory_consumption_watcher.rb
Instance Attribute Summary collapse
-
#memory_limit ⇒ Object
readonly
Returns the value of attribute memory_limit.
-
#world ⇒ Object
readonly
Returns the value of attribute world.
Instance Method Summary collapse
- #check_memory_state ⇒ Object
-
#initialize(world, memory_limit, options) ⇒ MemoryConsumptionWatcher
constructor
A new instance of MemoryConsumptionWatcher.
- #set_timer(interval = @polling_interval) ⇒ Object
Constructor Details
#initialize(world, memory_limit, options) ⇒ MemoryConsumptionWatcher
Returns a new instance of MemoryConsumptionWatcher.
10 11 12 13 14 15 16 17 18 |
# File 'lib/dynflow/watchers/memory_consumption_watcher.rb', line 10 def initialize(world, memory_limit, ) @memory_limit = memory_limit @world = world @polling_interval = [:polling_interval] || 60 @memory_info_provider = [:memory_info_provider] || GetProcessMem.new @memory_checked_callback = [:memory_checked_callback] @memory_limit_exceeded_callback = [:memory_limit_exceeded_callback] set_timer [:initial_wait] || @polling_interval end |
Instance Attribute Details
#memory_limit ⇒ Object (readonly)
Returns the value of attribute memory_limit.
8 9 10 |
# File 'lib/dynflow/watchers/memory_consumption_watcher.rb', line 8 def memory_limit @memory_limit end |
#world ⇒ Object (readonly)
Returns the value of attribute world.
8 9 10 |
# File 'lib/dynflow/watchers/memory_consumption_watcher.rb', line 8 def world @world end |
Instance Method Details
#check_memory_state ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/dynflow/watchers/memory_consumption_watcher.rb', line 20 def check_memory_state current_memory = @memory_info_provider.bytes if current_memory > @memory_limit @memory_limit_exceeded_callback.call(current_memory, @memory_limit) if @memory_limit_exceeded_callback # terminate the world and stop polling world.terminate else @memory_checked_callback.call(current_memory, @memory_limit) if @memory_checked_callback # memory is under the limit - keep waiting set_timer end end |
#set_timer(interval = @polling_interval) ⇒ Object
33 34 35 |
# File 'lib/dynflow/watchers/memory_consumption_watcher.rb', line 33 def set_timer(interval = @polling_interval) @world.clock.ping(self, interval, nil, :check_memory_state) end |