Sha256: ead68810b70773cab054bc2d8e5379e6fff7f90615119d91e3dc462d8f84cbf7

Contents?: true

Size: 880 Bytes

Versions: 1

Compression:

Stored size: 880 Bytes

Contents

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
        set_timer options[:initial_wait] || @polling_interval
      end

      def check_memory_state
        if @memory_info_provider.bytes > @memory_limit
          # terminate the world and stop polling
          world.terminate
        else
          # 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

1 entries across 1 versions & 1 rubygems

Version Path
dynflow-0.8.22 lib/dynflow/watchers/memory_consumption_watcher.rb