Module: Berkshelf::API::Application
- Extended by:
- Logging, Mixin::Services, Forwardable
- Defined in:
- lib/berkshelf/api/application.rb
Class Attribute Summary collapse
-
.start_time ⇒ Object
readonly
Returns the value of attribute start_time.
Class Method Summary collapse
- .config ⇒ Berkshelf::API::Config
-
.configure(options = {}) ⇒ Berkshelf::API::Config
Configure the application.
- .configure_logger(options = {}) ⇒ Object
- .home_path ⇒ String
-
.instance ⇒ Berkshelf::API::Application
Retrieve the running instance of the Application.
-
.registry ⇒ Celluloid::Registry
The Actor registry for Berkshelf::API.
-
.run(options = {}) ⇒ Object
Run the application in the foreground (sleep on main thread).
-
.run!(options = {}) ⇒ Berkshelf::API::Application
Run the application in the background.
- .running? ⇒ Boolean
- .set_config(config) ⇒ Object
-
.shutdown ⇒ Object
Shutdown the running instance.
Methods included from Mixin::Services
Methods included from Logging
Class Attribute Details
.start_time ⇒ Object (readonly)
Returns the value of attribute start_time.
31 32 33 |
# File 'lib/berkshelf/api/application.rb', line 31 def start_time @start_time end |
Class Method Details
.config ⇒ Berkshelf::API::Config
35 36 37 38 39 40 41 |
# 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 = {}) ⇒ Berkshelf::API::Config
Configure the application
63 64 65 66 67 68 69 70 71 72 |
# File 'lib/berkshelf/api/application.rb', line 63 def configure( = {}) unless [:config_file].nil? set_config Berkshelf::API::Config.from_file([:config_file]) end configure_logger() config rescue Buff::Errors::ConfigNotFound => ex raise ConfigNotFoundError, ex end |
.configure_logger(options = {}) ⇒ Object
81 82 83 |
# File 'lib/berkshelf/api/application.rb', line 81 def configure_logger( = {}) Logging.init(level: [:log_level], location: [:log_location]) end |
.home_path ⇒ String
86 87 88 |
# File 'lib/berkshelf/api/application.rb', line 86 def home_path ENV['BERKSHELF_API_PATH'] || config.home_path end |
.instance ⇒ Berkshelf::API::Application
Retrieve the running instance of the Application
95 96 97 98 99 |
# File 'lib/berkshelf/api/application.rb', line 95 def instance return @instance if @instance raise NotStartedError, "application not running" end |
.registry ⇒ Celluloid::Registry
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[].
The Actor registry for Berkshelf::API.
108 109 110 |
# File 'lib/berkshelf/api/application.rb', line 108 def registry @registry ||= Celluloid::Registry.new end |
.run(options = {}) ⇒ Object
Run the application in the foreground (sleep on main thread)
116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 |
# File 'lib/berkshelf/api/application.rb', line 116 def run( = {}) @start_time = Time.now.utc loop do supervisor = run!() while supervisor.alive? sleep 0.1 instance.terminate if @shutdown end break if @shutdown log.error "!!! #{self} crashed. Restarting..." end end |
.run!(options = {}) ⇒ Berkshelf::API::Application
Run the application in the background
140 141 142 143 144 145 146 |
# File 'lib/berkshelf/api/application.rb', line 140 def run!( = {}) = { disable_http: false, eager_build: false }.merge() configure() @instance = ApplicationSupervisor.new(registry, ) cache_builder.async(:build_loop) if [:eager_build] @instance end |
.running? ⇒ Boolean
149 150 151 152 153 |
# File 'lib/berkshelf/api/application.rb', line 149 def running? instance.alive? rescue NotStartedError false end |
.set_config(config) ⇒ Object
44 45 46 |
# File 'lib/berkshelf/api/application.rb', line 44 def set_config(config) @config = config end |
.shutdown ⇒ Object
Shutdown the running instance
159 160 161 |
# File 'lib/berkshelf/api/application.rb', line 159 def shutdown @shutdown = true end |