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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 59a90fdb765825b3e33cf5de6ceec5ffba64975aec6ec17062c18f53ca47e350
4
- data.tar.gz: 30a111bd424743bbe3303fbd76651c160f2f2baae535dbcf1cc243be3339c6b5
3
+ metadata.gz: f0e4c0d383c1c9a61fccd6805a66edd6a0113ea9ede561b9e77083c8df75ec75
4
+ data.tar.gz: 15ebc93883d4154eb37c0aacd85067f3608fbae7fa98103a67e7abf4323f73b0
5
5
  SHA512:
6
- metadata.gz: 9c185d646afc5c8ae430e2160f794b3dd29599ab711a5defdbcc0fa669ccac0b09baaa0a1fc0ad0b889400039b59f6c95cd3b5278fdb36c026aa8f74221ef79a
7
- data.tar.gz: efe2370a36301f6e222037497ee8374d5997499de82dbb2d6a6da20150474598aab99d7cc0035a32cea494bf576ab4ceeaf026b97903dc8ffa782aa6e58923f3
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
- start
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
- path = File.dirname(file_path)
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
28
+ start_internal(enable_listen_thread?)
29
+ end
30
+ deprecate :start, deprecator: ActiveSupport::Deprecation.new('1.0', 'ProcessSettings') # will become private
38
31
 
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
32
+ private
43
33
 
44
- load_statically_targeted_settings
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
- private
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ProcessSettings
4
- VERSION = '0.11.0.pre.1'
4
+ VERSION = '0.11.0.pre.6'
5
5
  end
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.11.0.pre.1
4
+ version: 0.11.0.pre.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Invoca