process_settings 0.11.0.pre.5 → 0.11.1.pre.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ada8f710e24244a34005a22536e106cf086863b110d1908f58503df01797dedb
4
- data.tar.gz: ae8fa6f78f2d4894a81f4e806b8408790520c38b0a19df723fe4a572eb3ffea4
3
+ metadata.gz: 074a7a2fc453de9cd6f46546ebe6040c61ebc2532df5bcfa07cb6841b70ef793
4
+ data.tar.gz: 01b1658b4a8d7cef95367cc91685c544417fac81633a736cbab87d791dda17ba
5
5
  SHA512:
6
- metadata.gz: 5f58df6d01c42db7ec61b2c2815d3fdbe9cc8552e754edcad4e40a63816bbb6a621290acf2c0c636f87902e8fc10f28fc5330e4fd7250f8755e7d4c22f090304
7
- data.tar.gz: 5a9ef3528655fbe57d3d23d9a2714fdc3223f9cc7234237cd20beb0f26891571f444d5a325bc2df1d9bfbff8e117b67ad769c797b2033c838c88064dc1bb567c
6
+ metadata.gz: 0025db7a10cc0157579a3bb3890b092626f613e01da5dd132e9017e634393b7fa15eb724070be939fe17e37816df08c43585dbdecf37f0437fd5b25261dc3874
7
+ data.tar.gz: c517c8d7e7d96f17e1fb1de6e0484793cbc9e9ae32add2238b48fae6b4619cb862e03ba7d3786490134acf1226f41db2b4bf204b4862010e51d5a1fc5c16e26f
data/README.md CHANGED
@@ -126,16 +126,20 @@ The simplest approach--as shown above--is to read the latest settings at any tim
126
126
  http_version = ProcessSettings['frontend', 'http_version']
127
127
  ```
128
128
 
129
- #### Register an `on_change` Callback
130
- Alternatively, if you need to execute some code when there is a change, register a callback with `ProcessSettings.instance#on_change`:
129
+ #### Register a `when_updated` Callback
130
+ Alternatively, if you need to execute initially and whenever the value is updated, register a callback with `ProcessSettings.instance#when_updated`:
131
131
  ```
132
- ProcessSettings.instance.on_change do
132
+ ProcessSettings.instance.when_updated do
133
133
  logger.level = ProcessSettings['frontend', 'log_level']
134
134
  end
135
135
  ```
136
- Note that all callbacks run sequentially on the shared change monitoring thread, so please be considerate!
136
+ By default, the `when_updated` block is called initially when registered. We've found this to be convenient in most cases; it can be disabled by passing `initial_update: false`, in which case the block will be called 0 or more times in the future, when any of the process settings for this process change.
137
+
138
+ `when_updated` is idempotent.
137
139
 
138
- There is no provision for unregistering callbacks. Instead, replace the `instance` of the monitor with a new one.
140
+ In case you need to cancel the callback later, `when_updated` returns a handle (the block itself) which can later be passed into `cancel_when_updated`.
141
+
142
+ Note that all callbacks run sequentially on the shared change monitoring thread, so please be considerate!
139
143
 
140
144
  ## Targeting
141
145
  Each settings YAML file has an optional `target` key at the top level, next to `settings`.
@@ -13,7 +13,7 @@ module ProcessSettings
13
13
  class FileMonitor < AbstractMonitor
14
14
  attr_reader :file_path, :untargeted_settings
15
15
 
16
- def initialize(file_path, logger:)
16
+ def initialize(file_path, logger:, environment: nil)
17
17
  super(logger: logger)
18
18
 
19
19
  @file_path = File.expand_path(file_path)
@@ -21,7 +21,7 @@ module ProcessSettings
21
21
  @untargeted_settings = nil
22
22
  @last_untargetted_settings = nil
23
23
 
24
- start_internal(enable_listen_thread?)
24
+ start_internal(enable_listen_thread?(environment))
25
25
  end
26
26
 
27
27
  def start
@@ -29,8 +29,29 @@ module ProcessSettings
29
29
  end
30
30
  deprecate :start, deprecator: ActiveSupport::Deprecation.new('1.0', 'ProcessSettings') # will become private
31
31
 
32
+ def listen_thread_running?
33
+ !@listener.nil?
34
+ end
35
+
32
36
  private
33
37
 
38
+ def enable_listen_thread?(environment = nil)
39
+ !disable_listen_thread?(environment)
40
+ end
41
+
42
+ def disable_listen_thread?(environment = nil)
43
+ case ENV['DISABLE_LISTEN_CHANGE_MONITORING']
44
+ when 'true', '1'
45
+ true
46
+ when 'false', '0'
47
+ false
48
+ when nil
49
+ (environment || service_env) == 'test'
50
+ else
51
+ raise ArgumentError, "DISABLE_LISTEN_CHANGE_MONITORING has unknown value #{ENV['DISABLE_LISTEN_CHANGE_MONITORING'].inspect}"
52
+ end
53
+ end
54
+
34
55
  # optionally starts listening for changes, then loads current settings
35
56
  # Note: If with_listen_thread is truthy, this method creates a new thread that will be
36
57
  # monitoring for changes.
@@ -65,29 +86,13 @@ module ProcessSettings
65
86
  # stops listening for changes
66
87
  def stop
67
88
  @listener&.stop
68
- end
69
-
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
89
+ @listener = nil
85
90
  end
86
91
 
87
92
  def service_env
88
- if defined?(Rails) && Rails.respond_to(:env)
93
+ if defined?(Rails) && Rails.respond_to?(:env)
89
94
  Rails.env
90
- end || ENV['SERVICE_ENV']
95
+ end || ENV['RAILS_ENV'] || ENV['SERVICE_ENV']
91
96
  end
92
97
 
93
98
  # Loads the most recent settings from disk
@@ -12,10 +12,10 @@ module ProcessSettings
12
12
  class << self
13
13
  def included(including_klass)
14
14
  after_method =
15
- if including_klass.respond_to?(:teardown)
16
- :teardown
17
- else
15
+ if including_klass.respond_to?(:after)
18
16
  :after
17
+ else
18
+ :teardown
19
19
  end
20
20
 
21
21
  including_klass.send(after_method) do
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ProcessSettings
4
- VERSION = '0.11.0.pre.5'
4
+ VERSION = '0.11.1.pre.1'
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.5
4
+ version: 0.11.1.pre.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Invoca