Sha256: 5cea5b896037e6260a23e2e775a95dc71ec37622a56ab2c04928b19ab5b98221
Contents?: true
Size: 1.28 KB
Versions: 25
Compression:
Stored size: 1.28 KB
Contents
# frozen_string_literal: true require 'get_process_mem' module Dynflow module Watchers class MemoryConsumptionWatcher attr_reader :memory_limit, :world 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 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 def set_timer(interval = @polling_interval) @world.clock.ping(self, interval, nil, :check_memory_state) end end end end
Version data entries
25 entries across 25 versions & 1 rubygems