process_settings 0.11.0.pre.4 → 0.11.0

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: 00cb781d3385028324b7dd6f55e12da7550901107adf78ee57abde78987335b4
4
- data.tar.gz: b8ae66252379583f2ac9a8da599e54d559fbd92d4d40b12d36faa6539114e511
3
+ metadata.gz: 325c0d9bcbdf24e24b98ff61ceb8f66c7a86eedf659703fa1696a9969fc20399
4
+ data.tar.gz: fcd0872ad94d1b6946fd577bbe3aaff376febf449f282f149b4cbb40f00cfaaa
5
5
  SHA512:
6
- metadata.gz: c0229a56f9a6e8f6fe20fa0b19cdb82f2df4d82dbd3abd0c7d74cd0b136200e7ac48a261252b60fcd467f6b0c8a8967e8b62e6237f8cf737d871edbc8c0db189
7
- data.tar.gz: 528650ea37e3fa716b588d76d5cef31af6e06e6d5fd506b4f7b65f13d51e38fd45a3f65a3c004cff0e294df47ec9397c29870dd26cdba0ea05ec5b80ef21bb3e
6
+ metadata.gz: 9b114a06259666f47cb8f052354655ac0ece1f29dafd1ddf4939eb5c197e97aafca65af0c4c3a8ee383d2d739caef0769226d38365f48687410a001f1054bae4
7
+ data.tar.gz: f09a461c8826e55797c67c6222084510933ba30d4c2696c82ff4193a0d22bf1c011a1112a703c2bf3582e68af6e258f6ee93adee2d505a71981c7715c0f59970
@@ -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,65 +21,78 @@ 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
+ private
37
+
38
+ def enable_listen_thread?(environment = nil)
39
+ !disable_listen_thread?(environment)
63
40
  end
64
41
 
65
- def disable_listen_thread?
42
+ def disable_listen_thread?(environment = nil)
66
43
  case ENV['DISABLE_LISTEN_CHANGE_MONITORING']
67
44
  when 'true', '1'
68
45
  true
69
46
  when 'false', '0'
70
47
  false
71
48
  when nil
72
- service_env == 'test'
49
+ (environment || service_env) == 'test'
73
50
  else
74
51
  raise ArgumentError, "DISABLE_LISTEN_CHANGE_MONITORING has unknown value #{ENV['DISABLE_LISTEN_CHANGE_MONITORING'].inspect}"
75
52
  end
76
53
  end
77
54
 
78
- private
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
79
91
 
80
92
  def service_env
81
- (defined?(Rails) && Rails.env) || 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.4'
4
+ VERSION = '0.11.0'
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.4
4
+ version: 0.11.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: 1.3.1
113
+ version: '0'
114
114
  requirements: []
115
115
  rubygems_version: 3.0.3
116
116
  signing_key: