class Asynchronic::GarbageCollector
Attributes
conditions[R]
environment[R]
timeout[R]
Public Class Methods
new(environment, timeout)
click to toggle source
# File lib/asynchronic/garbage_collector.rb, line 4 def initialize(environment, timeout) @environment = environment @timeout = timeout @running = false @conditions = {} end
Public Instance Methods
add_condition(name, &block)
click to toggle source
# File lib/asynchronic/garbage_collector.rb, line 42 def add_condition(name, &block) conditions[name] = block end
conditions_names()
click to toggle source
# File lib/asynchronic/garbage_collector.rb, line 50 def conditions_names conditions.keys end
remove_condition(name)
click to toggle source
# File lib/asynchronic/garbage_collector.rb, line 46 def remove_condition(name) conditions.delete name end
start()
click to toggle source
# File lib/asynchronic/garbage_collector.rb, line 11 def start Asynchronic.logger.info('Asynchronic') { 'Starting GC' } Signal.trap('QUIT') { stop } @running = true while @running processes = environment.processes processes.each(&:abort_if_dead) conditions.each do |name, condition| Asynchronic.logger.info('Asynchronic') { "Running GC - #{name}" } begin processes.select(&condition).each(&:destroy) rescue => ex error_message = "#{ex.class}: #{ex.message}\n#{ex.backtrace.join("\n")}" Asynchronic.logger.error('Asynchronic') { error_message } end end wait end end
stop()
click to toggle source
# File lib/asynchronic/garbage_collector.rb, line 37 def stop Asynchronic.logger.info('Asynchronic') { 'Stopping GC' } @running = false end
Private Instance Methods
wait()
click to toggle source
# File lib/asynchronic/garbage_collector.rb, line 58 def wait Asynchronic.logger.info('Asynchronic') { 'Sleeping GC' } sleep timeout end