-
-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathsetup.rb
More file actions
81 lines (69 loc) · 2.12 KB
/
setup.rb
File metadata and controls
81 lines (69 loc) · 2.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# frozen_string_literal: true
module Html2rss
module Web
module Boot
##
# Applies boot-time runtime configuration outside the Roda class body.
module Setup
RACK_TIMEOUT_BUFFER_SECONDS = 5
class << self
# @return [Boolean]
def sentry_enabled?
RuntimeEnv.sentry_enabled?
end
# Validates environment configuration and wires the request service.
#
# @return [void]
def call!
validate_environment!
capture_runtime_env!
configure_sentry!
configure_request_service!
configure_runtime_logging!
log_startup!
end
private
# @return [void]
def validate_environment!
EnvironmentValidator.validate_environment!
EnvironmentValidator.validate_production_security!
Flags.validate!
end
# @return [void]
def capture_runtime_env!
RuntimeEnv.capture!
end
# @return [void]
def configure_sentry!
Sentry.configure!
end
# @return [void]
def configure_request_service!
return unless defined?(Rack::Timeout)
return unless Rack::Timeout.respond_to?(:service_timeout=)
Rack::Timeout.service_timeout =
Html2rss::RequestService::Policy::DEFAULTS[:total_timeout_seconds] +
RACK_TIMEOUT_BUFFER_SECONDS
end
# @return [void]
def configure_runtime_logging!
return unless defined?(Rack::Timeout::Logger)
Rack::Timeout::Logger.logger = AppLogger.logger
end
# @return [void]
def log_startup!
AppLogger.logger.info(
{
component: 'boot',
event_name: 'app.start',
build_tag: RuntimeEnv.build_tag,
git_sha: RuntimeEnv.git_sha,
sentry_enabled: RuntimeEnv.sentry_enabled?
}.to_json
)
end
end
end
end
end
end