process_settings 0.11.0.pre.3 → 0.11.0.pre.8

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