module Berkshelf::API::Application
Attributes
Public Class Methods
@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 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
@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
@return [String]
# File lib/berkshelf/api/application.rb, line 86 def home_path ENV['BERKSHELF_API_PATH'] || config.home_path end
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
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 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 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
@return [Boolean]
# File lib/berkshelf/api/application.rb, line 149 def running? instance.alive? rescue NotStartedError false end
@param [Berkshelf::API::Config] config
# File lib/berkshelf/api/application.rb, line 44 def set_config(config) @config = config end
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