process_settings 0.14.0 → 0.15.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/process_settings/abstract_monitor.rb +33 -5
- data/lib/process_settings/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 17af8e8b00a219e790b36fc20282e0c4c7d7c04cfd7f911ea636f056b675cf70
|
|
4
|
+
data.tar.gz: 198665150f57b95634698ab3474dd587dbefbc48ecf41d10084a6f872a0a3949
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: ea2bf7c35886a10807a3b8ab171133776c1381371b628ac08cbe413a2cbc8d4bc8c600142fc44c0734fb1e2dc6bb2143be40c68c5b99217404fa6a085ccf2326
|
|
7
|
+
data.tar.gz: b92dbd32b2935e7d3ba4b8b95f33dc032e018a273505f7daaba4126d1ef7f132fe40e79535780c45a3283df9daa3c006ce1312c2cf2c2eb472b7b123f09fa10f
|
|
@@ -11,14 +11,16 @@ module ProcessSettings
|
|
|
11
11
|
OnChangeDeprecation = ActiveSupport::Deprecation.new('1.0', 'ProcessSettings::Monitor')
|
|
12
12
|
|
|
13
13
|
class AbstractMonitor
|
|
14
|
+
|
|
14
15
|
attr_reader :min_polling_seconds, :logger
|
|
15
|
-
attr_reader :static_context, :statically_targeted_settings
|
|
16
|
+
attr_reader :static_context, :statically_targeted_settings, :full_context_cache
|
|
16
17
|
|
|
17
18
|
def initialize(logger:)
|
|
18
19
|
@logger = logger or raise ArgumentError, "logger must be not be nil"
|
|
19
20
|
@on_change_callbacks = []
|
|
20
21
|
@when_updated_blocks = Set.new
|
|
21
22
|
@static_context = {}
|
|
23
|
+
@full_context_cache = {}
|
|
22
24
|
end
|
|
23
25
|
|
|
24
26
|
# This is the main entry point for looking up settings on the Monitor instance.
|
|
@@ -94,10 +96,20 @@ module ProcessSettings
|
|
|
94
96
|
def targeted_value(*path, dynamic_context:, required: true)
|
|
95
97
|
# Merging the static context in is necessary to make sure that the static context isn't shifting
|
|
96
98
|
# this can be rather costly to do every time if the dynamic context is not changing
|
|
97
|
-
|
|
98
|
-
#
|
|
99
|
-
|
|
100
|
-
|
|
99
|
+
|
|
100
|
+
# Warn in the case where dynamic context was attempting to change a static value
|
|
101
|
+
changes = dynamic_context.each_with_object({}) do |(key, dynamic_value), result|
|
|
102
|
+
if static_context.has_key?(key)
|
|
103
|
+
static_value = static_context[key]
|
|
104
|
+
if static_value != dynamic_value
|
|
105
|
+
result[key] = [static_value, dynamic_value]
|
|
106
|
+
end
|
|
107
|
+
end
|
|
108
|
+
end
|
|
109
|
+
|
|
110
|
+
changes.empty? or warn("WARNING: static context overwritten by dynamic!\n#{changes.inspect}")
|
|
111
|
+
|
|
112
|
+
full_context = full_context_from_cache(dynamic_context)
|
|
101
113
|
result = statically_targeted_settings.reduce(:not_found) do |latest_result, target_and_settings|
|
|
102
114
|
# find last value from matching targets
|
|
103
115
|
if target_and_settings.target.target_key_matches?(full_context)
|
|
@@ -119,6 +131,22 @@ module ProcessSettings
|
|
|
119
131
|
end
|
|
120
132
|
end
|
|
121
133
|
|
|
134
|
+
def full_context_from_cache(dynamic_context)
|
|
135
|
+
if (full_context = full_context_cache[dynamic_context])
|
|
136
|
+
logger.info("cache hit ...")
|
|
137
|
+
full_context
|
|
138
|
+
else
|
|
139
|
+
logger.info("cache miss ...")
|
|
140
|
+
dynamic_context.deep_merge(static_context).tap do |full_context|
|
|
141
|
+
if full_context_cache.size <= 1000
|
|
142
|
+
full_context_cache[dynamic_context] = full_context
|
|
143
|
+
else
|
|
144
|
+
logger.info("cache limit reached ...")
|
|
145
|
+
end
|
|
146
|
+
end
|
|
147
|
+
end
|
|
148
|
+
end
|
|
149
|
+
|
|
122
150
|
private
|
|
123
151
|
|
|
124
152
|
class << self
|