Module: Cybertrain::Runtime
- Defined in:
- cybertrain/runtime.rb
Overview
The process-shared settings of the booted Application.
Class Method Summary collapse
-
.applied ⇒ Integer
How many times Runtime.apply has run in this process: 0 until the first boot.
-
.apply_logging(config) ⇒ String
Installs the log level on Cybertrain.logger (
:noneas:error: no request log, errors still printed) and the line format (Logger.json_lines). -
.apply_zone(config) ⇒ String
Installs
config.time_zoneasTime.zone(Clock.zone), the one setting a process that does not boot needs too: Runtime.apply calls it, and so do a registered command (Main.command),jobsandconsole, which run without Application#boot. -
.describe ⇒ String
The settings as one line, for a test to compare two states (and for a bug report): every value Runtime.apply and Application.configure_views write, in a fixed order, except I18n’s four, which I18n answers itself (I18n.default_locale, I18n.available_locales).
-
.reset! ⇒ nil
Puts every setting Runtime.apply and Application.configure_views write back to its default, as in a process that has not booted: for a test that boots Applications with different configs and wants each case to start from the same state.
-
.role ⇒ String
The role running now (“server”, “worker”, “feeds”), or “”.
Class Method Details
.applied ⇒ Integer
How many times apply has run in this process: 0 until the first boot. A second boot of the same Application counts again.
168 169 170 |
# File 'cybertrain/runtime.rb', line 168 def self.applied @applied end |
.apply_logging(config) ⇒ String
Installs the log level on Cybertrain.logger (:none as :error: no
request log, errors still printed) and the line format
(Logger.json_lines). apply calls it, and so do a registered command
(Main.command), jobs and console, which run without
Application#boot, so their lines follow log_level and log_format
too. An unknown level or format is refused as boot refuses it:
nothing is changed and the answer is Config#log_error’s message,
which the caller prints as boot does (error: ...) before exiting 1.
107 108 109 110 111 112 113 114 |
# File 'cybertrain/runtime.rb', line 107 def self.apply_logging(config) problem = config.log_error return problem unless problem.empty? Cybertrain.logger.level = config.log_level == :none ? :error : config.log_level Logger.json_lines = config.log_format == :json "" end |
.apply_zone(config) ⇒ String
Installs config.time_zone as Time.zone (Clock.zone), the one
setting a process that does not boot needs too: apply calls it,
and so do a registered command (Main.command), jobs and
console, which run without Application#boot. An unknown name is
refused as boot refuses it: the zone is left as it was and the answer
is Config#time_zone_error’s message, which the caller prints as
boot does (error: ...) before exiting 1.
126 127 128 129 130 131 132 |
# File 'cybertrain/runtime.rb', line 126 def self.apply_zone(config) problem = config.time_zone_error return problem unless problem.empty? Clock.zone = TimeZone.find(config.time_zone) "" end |
.describe ⇒ String
The settings as one line, for a test to compare two states (and for a bug report): every value apply and Application.configure_views write, in a fixed order, except I18n’s four, which I18n answers itself (I18n.default_locale, I18n.available_locales).
178 179 180 181 182 183 184 185 186 187 188 |
# File 'cybertrain/runtime.rb', line 178 def self.describe views = Views.engine.nil? ? "none" : "configured" "views=#{views} layout=#{Views.layout_name} " \ "assets_raise=#{Assets.raise_on_unknown} assets_kept=#{Assets.kept_count} " \ "max_upload_bytes=#{Multipart.max_upload_bytes} max_parts=#{Multipart.max_parts} " \ "upload_root=#{BlobStore.root} max_page=#{Params.max_page} " \ "trusted_proxy=#{Request.trusted_proxy} trusted_proxies=#{Request.trusted_proxies.join(",")} " \ "filter_parameters=#{ParameterFilter.names.join(",")} " \ "permissions_policy=#{Response.} " \ "log_level=#{Cybertrain.logger.level} log_format=#{Logger.json_lines ? "json" : "text"} time_zone=#{Clock.zone.zone_name}" end |
.reset! ⇒ nil
Puts every setting apply and Application.configure_views write back to its default, as in a process that has not booted: for a test that boots Applications with different configs and wants each case to start from the same state. It leaves the configuration (Cybertrain.config), the registrations (job handlers, helpers, asset tables) and the database connection alone.
142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 |
# File 'cybertrain/runtime.rb', line 142 def self.reset! Views.reset! Assets.forget_kept Assets.raise_on_unknown = true Multipart.configure(DEFAULT_MAX_UPLOAD_BYTES, DEFAULT_MAX_PARTS) BlobStore.root = DEFAULT_UPLOAD_ROOT Params.max_page = DEFAULT_MAX_PAGE Request.trusted_proxy = false Request.trusted_proxies = Array.new(0) { "" } ParameterFilter.names = ParameterFilter::DEFAULT_NAMES Response. = DEFAULT_PERMISSIONS_POLICY Cybertrain.logger.level = :info Logger.json_lines = false I18n.default_locale = DEFAULT_LOCALE I18n.available_locales = [DEFAULT_LOCALE] I18n.raise_on_missing = false I18n.mark_missing = true Clock.zone = TimeZone::UTC @role = "" nil end |
.role ⇒ String
Returns the role running now (“server”, “worker”, “feeds”), or “”.
226 227 228 |
# File 'cybertrain/runtime.rb', line 226 def self.role @role end |