class QuickML::Sweeper

Public Class Methods

new(config) click to toggle source
# File vendor/qwik/lib/qwik/ml-sweeper.rb, line 16
def initialize (config)
  @config = config
  @status = :safe
  @logger = @config.logger
end

Private Class Methods

ml_file?(filename) click to toggle source
# File vendor/qwik/lib/qwik/ml-sweeper.rb, line 63
def self.ml_file? (filename)
  return false if File.file?(filename)
  return false if /\./ =~ File.basename(filename) # avoid the name with dot
  return true
end
mladdress(name, ml_domain) click to toggle source
# File vendor/qwik/lib/qwik/ml-sweeper.rb, line 69
def self.mladdress (name, ml_domain)
  return "#{name}@#{ml_domain}"
end

Public Instance Methods

shutdown() click to toggle source
# File vendor/qwik/lib/qwik/ml-sweeper.rb, line 35
def shutdown
  until @status == :safe
    sleep(0.5)
  end
  @logger.vlog 'Sweeper shutdown'
end
start() click to toggle source
# File vendor/qwik/lib/qwik/ml-sweeper.rb, line 22
def start
  @logger.vlog 'Sweeper started'
  loop {
    sleep(@config.sweep_interval)
    begin
      sweep
    rescue Exception => e
      @logger.log "Unknown Sweep Error: #{e.class}: #{e.message}"
      @logger.log e.backtrace
    end
  }
end

Private Instance Methods

sweep() click to toggle source
# File vendor/qwik/lib/qwik/ml-sweeper.rb, line 44
def sweep
  @status = :sweeping
  @logger.vlog 'Sweeper runs'
  Dir.new(@config.sites_dir).each {|filename|
    filename = File.join(@config.sites_dir, filename)
    if Sweeper.ml_file?(filename)
      mlname = File.basename(filename)
      address = Sweeper.mladdress(mlname, @config.ml_domain)
      ServerMemory.ml_mutex(@config, address).synchronize {
        ml = Group.new(@config, address)
        ml.group_config_check_exist
        sweep_ml(ml)
      }
    end
  }
  @logger.vlog 'Sweeper finished'
  @status = :safe
end
sweep_ml(ml) click to toggle source
# File vendor/qwik/lib/qwik/ml-sweeper.rb, line 73
def sweep_ml (ml)
  if ml.inactive?
    @logger.log "[#{ml.name}]: Inactive"
    #ml.close
    ml.close_dummy
  elsif ml.need_alert?
    ml.report_ml_close_soon
  end
end