module Berkshelf::API::Application

Attributes

start_time[R]

Public Class Methods

config() click to toggle source

@return [Berkshelf::API::Config]

# File lib/berkshelf/api/application.rb, line 35
def config
  @config ||= begin
    Berkshelf::API::Config.from_file(Berkshelf::API::Config.default_path)
  rescue
    Berkshelf::API::Config.new
  end
end
configure(options = {}) click to toggle source

Configure the application

@option options [String] :config_file

filepath to a configuration file to use

@option options [String, Fixnum] :log_location (STDOUT) @option options [String, nil] :log_level (“INFO”)

- "DEBUG
- "INFO"
- "WARN"
- "ERROR"
- "FATAL"

@raise [Berkshelf::API::ConfigNotFoundError]

@return [Berkshelf::API::Config]

# File lib/berkshelf/api/application.rb, line 63
def configure(options = {})
  unless options[:config_file].nil?
    set_config Berkshelf::API::Config.from_file(options[:config_file])
  end

  configure_logger(options)
  config
rescue Buff::Errors::ConfigNotFound => ex
  raise ConfigNotFoundError, ex
end
configure_logger(options = {}) click to toggle source

@option options [String, Fixnum] :log_location (STDOUT) @option options [String, nil] :log_level (“INFO”)

- "DEBUG
- "INFO"
- "WARN"
- "ERROR"
- "FATAL"
# File lib/berkshelf/api/application.rb, line 81
def configure_logger(options = {})
  Logging.init(level: options[:log_level], location: options[:log_location])
end
home_path() click to toggle source

@return [String]

# File lib/berkshelf/api/application.rb, line 86
def home_path
  ENV['BERKSHELF_API_PATH'] || config.home_path
end
instance() click to toggle source

Retrieve the running instance of the Application

@raise [Berkshelf::API::NotStartedError]

@return [Berkshelf::API::Application]

# File lib/berkshelf/api/application.rb, line 95
def instance
  return @instance if @instance

  raise NotStartedError, "application not running"
end
registry() click to toggle source

The Actor registry for Berkshelf::API.

@note Berkshelf::API uses it's own registry instead of Celluloid::Registry.root to

avoid conflicts in the larger namespace. Use Berkshelf::API::Application[] to access Berkshelf::API
actors instead of Celluloid::Actor[].

@return [Celluloid::Registry]

# File lib/berkshelf/api/application.rb, line 108
def registry
  @registry ||= Celluloid::Registry.new
end
run(options = {}) click to toggle source

Run the application in the foreground (sleep on main thread)

@option options [Boolean] :disable_http (false)

run the application without the rest gateway
# File lib/berkshelf/api/application.rb, line 116
def run(options = {})
  @start_time = Time.now.utc
  loop do
    supervisor = run!(options)

    while supervisor.alive?
      sleep 0.1
      instance.terminate if @shutdown
    end

    break if @shutdown

    log.error "!!! #{self} crashed. Restarting..."
  end
end
run!(options = {}) click to toggle source

Run the application in the background

@option options [Boolean] :disable_http (false)

run the application without the rest gateway

@option options [Boolean] :eager_build (false)

automatically begin and loop all cache builders

@return [Berkshelf::API::Application]

# File lib/berkshelf/api/application.rb, line 140
def run!(options = {})
  options = { disable_http: false, eager_build: false }.merge(options)
  configure(options)
  @instance = ApplicationSupervisor.new(registry, options)
  cache_builder.async(:build_loop) if options[:eager_build]
  @instance
end
running?() click to toggle source

@return [Boolean]

# File lib/berkshelf/api/application.rb, line 149
def running?
  instance.alive?
rescue NotStartedError
  false
end
set_config(config) click to toggle source

@param [Berkshelf::API::Config] config

# File lib/berkshelf/api/application.rb, line 44
def set_config(config)
  @config = config
end
shutdown() click to toggle source

Shutdown the running instance

@raise [Berkshelf::API::NotStartedError]

if there is no running instance
# File lib/berkshelf/api/application.rb, line 159
def shutdown
  @shutdown = true
end