process_settings 0.11.0.pre.1 → 0.11.0.pre.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/process_settings/file_monitor.rb +50 -20
- 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: f0e4c0d383c1c9a61fccd6805a66edd6a0113ea9ede561b9e77083c8df75ec75
|
4
|
+
data.tar.gz: 15ebc93883d4154eb37c0aacd85067f3608fbae7fa98103a67e7abf4323f73b0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fb39a3820a0ca9bf67ccefae886c58fa73dc47b875239ffe2dbfd59528635b0102cd88b25b7e80ba910035137b7f455ef4116f0f69c5f8c9ca359f896515ab82
|
7
|
+
data.tar.gz: 2f83adc49dbdc1968b75206ede61d900fba4197b2f333787020f4a4278d4a9d4494db88ae30f106205dc51056a78b3415d1ec69c1e13b9a235d445efad7776f5
|
@@ -3,6 +3,7 @@
|
|
3
3
|
require 'active_support'
|
4
4
|
require 'listen'
|
5
5
|
require 'psych'
|
6
|
+
require 'active_support/deprecation'
|
6
7
|
|
7
8
|
require 'process_settings/abstract_monitor'
|
8
9
|
require 'process_settings/targeted_settings'
|
@@ -20,32 +21,40 @@ module ProcessSettings
|
|
20
21
|
@untargeted_settings = nil
|
21
22
|
@last_untargetted_settings = nil
|
22
23
|
|
23
|
-
|
24
|
+
start_internal(enable_listen_thread?)
|
24
25
|
end
|
25
26
|
|
26
|
-
# starts listening for changes
|
27
|
-
# Note: This method creates a new thread that will be monitoring for changes
|
28
|
-
# do to the nature of how the Listen gem works, there is no record of
|
29
|
-
# existing threads, calling this mutliple times will result in spinning off
|
30
|
-
# multiple listen threads and will have unknow effects
|
31
27
|
def start
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
# 1. set up file watcher
|
36
|
-
# 2. start it (this should trigger if any changes have been made since (1))
|
37
|
-
# 3. load the file
|
28
|
+
start_internal(enable_listen_thread?)
|
29
|
+
end
|
30
|
+
deprecate :start, deprecator: ActiveSupport::Deprecation.new('1.0', 'ProcessSettings') # will become private
|
38
31
|
|
39
|
-
|
40
|
-
if modified.include?(file_path) || added.include?(file_path)
|
41
|
-
logger.info("ProcessSettings::Monitor file #{file_path} changed. Reloading.")
|
42
|
-
load_untargeted_settings
|
32
|
+
private
|
43
33
|
|
44
|
-
|
34
|
+
# optionally starts listening for changes, then loads current settings
|
35
|
+
# Note: If with_listen_thread is truthy, this method creates a new thread that will be
|
36
|
+
# monitoring for changes.
|
37
|
+
# Due to how the Listen gem works, there is no record of
|
38
|
+
# existing threads; calling this multiple times will result in spinning off
|
39
|
+
# multiple listen threads and will have unknown effects.
|
40
|
+
def start_internal(with_listen_thread)
|
41
|
+
if with_listen_thread
|
42
|
+
path = File.dirname(file_path)
|
43
|
+
|
44
|
+
# to eliminate any race condition:
|
45
|
+
# 1. set up file watcher
|
46
|
+
# 2. start it (this should trigger if any changes have been made since (1))
|
47
|
+
# 3. load the file
|
48
|
+
|
49
|
+
@listener = file_change_notifier.to(path) do |modified, added, _removed|
|
50
|
+
if modified.include?(file_path) || added.include?(file_path)
|
51
|
+
logger.info("ProcessSettings::Monitor file #{file_path} changed. Reloading.")
|
52
|
+
load_untargeted_settings
|
53
|
+
|
54
|
+
load_statically_targeted_settings
|
55
|
+
end
|
45
56
|
end
|
46
|
-
end
|
47
57
|
|
48
|
-
unless ENV['DISABLE_LISTEN_CHANGE_MONITORING']
|
49
58
|
@listener.start
|
50
59
|
end
|
51
60
|
|
@@ -58,7 +67,28 @@ module ProcessSettings
|
|
58
67
|
@listener&.stop
|
59
68
|
end
|
60
69
|
|
61
|
-
|
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
|
85
|
+
end
|
86
|
+
|
87
|
+
def service_env
|
88
|
+
if defined?(Rails) && Rails.respond_to?(:env)
|
89
|
+
Rails.env
|
90
|
+
end || ENV['SERVICE_ENV']
|
91
|
+
end
|
62
92
|
|
63
93
|
# Loads the most recent settings from disk
|
64
94
|
def load_untargeted_settings
|