process_settings 0.11.0.pre.2 → 0.11.0.pre.7
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/file_monitor.rb +47 -38
- 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: be2ecaa41e362b6bbdfdb93a2ad08ec6e61bb444b43a757acc2062ce3e666fbc
|
4
|
+
data.tar.gz: 4cdecb04dbde4ba79bd0dd41ae4e2a37591b8aa1c1bc09a6d5b2c23f0d3ec409
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4e23f89dd2cdc890074d3fdb3eac84702a6e791ecfa61bb954fb1ed1addda947f0f21041ce2f485e0808ca6fb75a5d7137663b8777434b22c1596f2def0c2bb1
|
7
|
+
data.tar.gz: 74e411fae551d1a14fb39e7cd1a769b2515a9e25bdf72844ba1d3c1510abd833bf3ae6ecd047bd21112746e9836bfc9d6da60616bba644532c44bfe30de90a32
|
@@ -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'
|
@@ -12,7 +13,7 @@ module ProcessSettings
|
|
12
13
|
class FileMonitor < AbstractMonitor
|
13
14
|
attr_reader :file_path, :untargeted_settings
|
14
15
|
|
15
|
-
def initialize(file_path, logger:)
|
16
|
+
def initialize(file_path, logger:, environment: nil)
|
16
17
|
super(logger: logger)
|
17
18
|
|
18
19
|
@file_path = File.expand_path(file_path)
|
@@ -20,56 +21,26 @@ module ProcessSettings
|
|
20
21
|
@untargeted_settings = nil
|
21
22
|
@last_untargetted_settings = nil
|
22
23
|
|
23
|
-
|
24
|
+
start_internal(enable_listen_thread?(environment))
|
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
|
-
# to eliminate any race condition:
|
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
|
38
|
-
|
39
|
-
@listener = file_change_notifier.to(path) do |modified, added, _removed|
|
40
|
-
if modified.include?(file_path) || added.include?(file_path)
|
41
|
-
logger.info("ProcessSettings::Monitor file #{file_path} changed. Reloading.")
|
42
|
-
load_untargeted_settings
|
43
|
-
|
44
|
-
load_statically_targeted_settings
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
48
|
-
if enable_listen_thread?
|
49
|
-
@listener.start
|
50
|
-
end
|
51
|
-
|
52
|
-
load_untargeted_settings
|
53
|
-
load_statically_targeted_settings
|
54
|
-
end
|
55
|
-
|
56
|
-
# stops listening for changes
|
57
|
-
def stop
|
58
|
-
@listener&.stop
|
28
|
+
start_internal(enable_listen_thread?)
|
59
29
|
end
|
30
|
+
deprecate :start, deprecator: ActiveSupport::Deprecation.new('1.0', 'ProcessSettings') # will become private
|
60
31
|
|
61
|
-
def enable_listen_thread?
|
32
|
+
def enable_listen_thread?(environment)
|
62
33
|
!disable_listen_thread?
|
63
34
|
end
|
64
35
|
|
65
|
-
def disable_listen_thread?
|
36
|
+
def disable_listen_thread?(environment = nil)
|
66
37
|
case ENV['DISABLE_LISTEN_CHANGE_MONITORING']
|
67
38
|
when 'true', '1'
|
68
39
|
true
|
69
40
|
when 'false', '0'
|
70
41
|
false
|
71
42
|
when nil
|
72
|
-
service_env == 'test'
|
43
|
+
environment || service_env == 'test'
|
73
44
|
else
|
74
45
|
raise ArgumentError, "DISABLE_LISTEN_CHANGE_MONITORING has unknown value #{ENV['DISABLE_LISTEN_CHANGE_MONITORING'].inspect}"
|
75
46
|
end
|
@@ -77,8 +48,46 @@ module ProcessSettings
|
|
77
48
|
|
78
49
|
private
|
79
50
|
|
51
|
+
# optionally starts listening for changes, then loads current settings
|
52
|
+
# Note: If with_listen_thread is truthy, this method creates a new thread that will be
|
53
|
+
# monitoring for changes.
|
54
|
+
# Due to how the Listen gem works, there is no record of
|
55
|
+
# existing threads; calling this multiple times will result in spinning off
|
56
|
+
# multiple listen threads and will have unknown effects.
|
57
|
+
def start_internal(with_listen_thread)
|
58
|
+
if with_listen_thread
|
59
|
+
path = File.dirname(file_path)
|
60
|
+
|
61
|
+
# to eliminate any race condition:
|
62
|
+
# 1. set up file watcher
|
63
|
+
# 2. start it (this should trigger if any changes have been made since (1))
|
64
|
+
# 3. load the file
|
65
|
+
|
66
|
+
@listener = file_change_notifier.to(path) do |modified, added, _removed|
|
67
|
+
if modified.include?(file_path) || added.include?(file_path)
|
68
|
+
logger.info("ProcessSettings::Monitor file #{file_path} changed. Reloading.")
|
69
|
+
load_untargeted_settings
|
70
|
+
|
71
|
+
load_statically_targeted_settings
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
@listener.start
|
76
|
+
end
|
77
|
+
|
78
|
+
load_untargeted_settings
|
79
|
+
load_statically_targeted_settings
|
80
|
+
end
|
81
|
+
|
82
|
+
# stops listening for changes
|
83
|
+
def stop
|
84
|
+
@listener&.stop
|
85
|
+
end
|
86
|
+
|
80
87
|
def service_env
|
81
|
-
|
88
|
+
if defined?(Rails) && Rails.respond_to?(:env)
|
89
|
+
Rails.env
|
90
|
+
end || ENV['RAILS_ENV'] || ENV['SERVICE_ENV']
|
82
91
|
end
|
83
92
|
|
84
93
|
# Loads the most recent settings from disk
|