class Aesop::Bootloader

Public Instance Methods

boot() click to toggle source
# File lib/aesop/bootloader.rb, line 4
def boot
  load_dispatchers
  begin
    if time = determine_latest_deploy_time
      Aesop::Logger.info("Last deployment was at #{Time.at(time)}")
      store_timestamp( time )
    end
  rescue => e
    raise Aesop::BootloaderException.new(e)
  end
end
deployment_file() click to toggle source
# File lib/aesop/bootloader.rb, line 62
def deployment_file
  self.configuration.deployment_file
end
determine_latest_deploy_time() click to toggle source
# File lib/aesop/bootloader.rb, line 16
def determine_latest_deploy_time
  file_time = read_deploy_time
  redis_time = read_current_timestamp

  if file_time
    if redis_time > 0
      reset_exceptions if file_time > redis_time
      [redis_time, file_time].max
    else
      reset_exceptions
      file_time
    end
  else
    redis_time ? redis_time : Time.now.to_i
  end
end
load_dispatchers() click to toggle source
# File lib/aesop/bootloader.rb, line 43
def load_dispatchers
  begin
    current_dir = File.dirname(__FILE__)
    Dir["#{current_dir}/dispatchers/**/*.rb"].each do |file|
      require File.expand_path(file)
    end
  rescue => e
    raise DispatcherLoadException.new(e)
  end
end
read_current_timestamp() click to toggle source
# File lib/aesop/bootloader.rb, line 54
def read_current_timestamp
  redis.get( configuration.deployment_key ).to_i
end
read_deploy_time() click to toggle source
# File lib/aesop/bootloader.rb, line 33
def read_deploy_time
  if File.exists?(deployment_file)
    File.open(deployment_file) do |file|
      file.read.to_i
    end
  else
    return nil
  end
end
redis() click to toggle source
# File lib/aesop/bootloader.rb, line 73
def redis
  Aesop.instance.redis
end
reset_exceptions() click to toggle source
# File lib/aesop/bootloader.rb, line 66
def reset_exceptions
  Aesop::Logger.debug("Resetting stored exception occurrences")
  redis.keys( "#{configuration.exception_prefix}:*" ).each do |key|
    redis.del key
  end
end
store_timestamp( time ) click to toggle source
# File lib/aesop/bootloader.rb, line 58
def store_timestamp( time )
  redis.set( configuration.deployment_key, time.to_i )
end