process_settings 0.11.0.pre.6 → 0.12.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +9 -5
- data/bin/combine_process_settings +1 -1
- data/lib/process_settings/file_monitor.rb +25 -20
- data/lib/process_settings/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0b0dcdddb2cb6813f10589b7284f4bbaae8a1d235d4bc23f181a7f7a7750659d
|
4
|
+
data.tar.gz: 84e9c90b0c30f7207be52afc9edc5dbc2382cf7f74ed16fecfbd023fd78268f9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 436bc2f85eda4c8584cd5853a0824646b6877e074116b8c4713952a2f94428a98b8d9120b095ba16645e635cbd72a399d84bbff53075c7974c76bb8d27521e07
|
7
|
+
data.tar.gz: 5356f8c93f2fd4b20fcc206aa8ab40c4ce89a8091fc827d9763050bb5fd316c3ecd7c763203f3181cd05b89cda3aefc4d180f70fc132f75b01cf25c79e049b8f
|
data/README.md
CHANGED
@@ -126,16 +126,20 @@ The simplest approach--as shown above--is to read the latest settings at any tim
|
|
126
126
|
http_version = ProcessSettings['frontend', 'http_version']
|
127
127
|
```
|
128
128
|
|
129
|
-
#### Register
|
130
|
-
Alternatively, if you need to execute
|
129
|
+
#### Register a `when_updated` Callback
|
130
|
+
Alternatively, if you need to execute initially and whenever the value is updated, register a callback with `ProcessSettings.instance#when_updated`:
|
131
131
|
```
|
132
|
-
ProcessSettings.instance.
|
132
|
+
ProcessSettings.instance.when_updated do
|
133
133
|
logger.level = ProcessSettings['frontend', 'log_level']
|
134
134
|
end
|
135
135
|
```
|
136
|
-
|
136
|
+
By default, the `when_updated` block is called initially when registered. We've found this to be convenient in most cases; it can be disabled by passing `initial_update: false`, in which case the block will be called 0 or more times in the future, when any of the process settings for this process change.
|
137
|
+
|
138
|
+
`when_updated` is idempotent.
|
137
139
|
|
138
|
-
|
140
|
+
In case you need to cancel the callback later, `when_updated` returns a handle (the block itself) which can later be passed into `cancel_when_updated`.
|
141
|
+
|
142
|
+
Note that all callbacks run sequentially on the shared change monitoring thread, so please be considerate!
|
139
143
|
|
140
144
|
## Targeting
|
141
145
|
Each settings YAML file has an optional `target` key at the top level, next to `settings`.
|
@@ -86,7 +86,7 @@ combined_settings = read_and_combine_settings(Pathname.new(options.root_folder)
|
|
86
86
|
version_number = options.version || default_version_number(options.initial_filename)
|
87
87
|
combined_settings << end_marker(version_number)
|
88
88
|
|
89
|
-
yaml = combined_settings.to_yaml
|
89
|
+
yaml = combined_settings.to_yaml.gsub(/: $/, ": null") # implicit null caused problems because of trailing whitespace
|
90
90
|
yaml_with_warning_comment = add_warning_comment(yaml, options.root_folder, PROGRAM_NAME, SETTINGS_FOLDER)
|
91
91
|
|
92
92
|
output_filename = options.output_filename
|
@@ -13,7 +13,7 @@ module ProcessSettings
|
|
13
13
|
class FileMonitor < AbstractMonitor
|
14
14
|
attr_reader :file_path, :untargeted_settings
|
15
15
|
|
16
|
-
def initialize(file_path, logger:)
|
16
|
+
def initialize(file_path, logger:, environment: nil)
|
17
17
|
super(logger: logger)
|
18
18
|
|
19
19
|
@file_path = File.expand_path(file_path)
|
@@ -21,7 +21,7 @@ module ProcessSettings
|
|
21
21
|
@untargeted_settings = nil
|
22
22
|
@last_untargetted_settings = nil
|
23
23
|
|
24
|
-
start_internal(enable_listen_thread?)
|
24
|
+
start_internal(enable_listen_thread?(environment))
|
25
25
|
end
|
26
26
|
|
27
27
|
def start
|
@@ -29,8 +29,29 @@ module ProcessSettings
|
|
29
29
|
end
|
30
30
|
deprecate :start, deprecator: ActiveSupport::Deprecation.new('1.0', 'ProcessSettings') # will become private
|
31
31
|
|
32
|
+
def listen_thread_running?
|
33
|
+
!@listener.nil?
|
34
|
+
end
|
35
|
+
|
32
36
|
private
|
33
37
|
|
38
|
+
def enable_listen_thread?(environment = nil)
|
39
|
+
!disable_listen_thread?(environment)
|
40
|
+
end
|
41
|
+
|
42
|
+
def disable_listen_thread?(environment = nil)
|
43
|
+
case ENV['DISABLE_LISTEN_CHANGE_MONITORING']
|
44
|
+
when 'true', '1'
|
45
|
+
true
|
46
|
+
when 'false', '0'
|
47
|
+
false
|
48
|
+
when nil
|
49
|
+
(environment || service_env) == 'test'
|
50
|
+
else
|
51
|
+
raise ArgumentError, "DISABLE_LISTEN_CHANGE_MONITORING has unknown value #{ENV['DISABLE_LISTEN_CHANGE_MONITORING'].inspect}"
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
34
55
|
# optionally starts listening for changes, then loads current settings
|
35
56
|
# Note: If with_listen_thread is truthy, this method creates a new thread that will be
|
36
57
|
# monitoring for changes.
|
@@ -65,29 +86,13 @@ module ProcessSettings
|
|
65
86
|
# stops listening for changes
|
66
87
|
def stop
|
67
88
|
@listener&.stop
|
68
|
-
|
69
|
-
|
70
|
-
def enable_listen_thread?
|
71
|
-
!disable_listen_thread?
|
72
|
-
end
|
73
|
-
|
74
|
-
def disable_listen_thread?
|
75
|
-
case ENV['DISABLE_LISTEN_CHANGE_MONITORING']
|
76
|
-
when 'true', '1'
|
77
|
-
true
|
78
|
-
when 'false', '0'
|
79
|
-
false
|
80
|
-
when nil
|
81
|
-
service_env == 'test'
|
82
|
-
else
|
83
|
-
raise ArgumentError, "DISABLE_LISTEN_CHANGE_MONITORING has unknown value #{ENV['DISABLE_LISTEN_CHANGE_MONITORING'].inspect}"
|
84
|
-
end
|
89
|
+
@listener = nil
|
85
90
|
end
|
86
91
|
|
87
92
|
def service_env
|
88
93
|
if defined?(Rails) && Rails.respond_to?(:env)
|
89
94
|
Rails.env
|
90
|
-
end || ENV['SERVICE_ENV']
|
95
|
+
end || ENV['RAILS_ENV'] || ENV['SERVICE_ENV']
|
91
96
|
end
|
92
97
|
|
93
98
|
# Loads the most recent settings from disk
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: process_settings
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.12.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Invoca
|
@@ -108,9 +108,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
108
108
|
version: '0'
|
109
109
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
110
110
|
requirements:
|
111
|
-
- - "
|
111
|
+
- - ">="
|
112
112
|
- !ruby/object:Gem::Version
|
113
|
-
version:
|
113
|
+
version: '0'
|
114
114
|
requirements: []
|
115
115
|
rubygems_version: 3.0.3
|
116
116
|
signing_key:
|