Class: Dynflow::Watchers::MemoryConsumptionWatcher

Inherits:
Object
  • Object
show all
Defined in:
lib/dynflow/watchers/memory_consumption_watcher.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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, options)
  @memory_limit = memory_limit
  @world = world
  @polling_interval = options[:polling_interval] || 60
  @memory_info_provider = options[:memory_info_provider] || GetProcessMem.new
  @memory_checked_callback = options[:memory_checked_callback]
  @memory_limit_exceeded_callback = options[:memory_limit_exceeded_callback]
  set_timer options[:initial_wait] || @polling_interval
end

Instance Attribute Details

#memory_limitObject (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

#worldObject (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_stateObject



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