process_settings 0.11.0.pre.7 → 0.13.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: be2ecaa41e362b6bbdfdb93a2ad08ec6e61bb444b43a757acc2062ce3e666fbc
4
- data.tar.gz: 4cdecb04dbde4ba79bd0dd41ae4e2a37591b8aa1c1bc09a6d5b2c23f0d3ec409
3
+ metadata.gz: 73aea1798bdb8d5624c5f66dc1c2282a53b1c32fce2409983b35429a7a7432c7
4
+ data.tar.gz: c6e2d24b5e79ec87a94e6bda783a9f933ae1ab3282c5f9d8291f2f873cdd4840
5
5
  SHA512:
6
- metadata.gz: 4e23f89dd2cdc890074d3fdb3eac84702a6e791ecfa61bb954fb1ed1addda947f0f21041ce2f485e0808ca6fb75a5d7137663b8777434b22c1596f2def0c2bb1
7
- data.tar.gz: 74e411fae551d1a14fb39e7cd1a769b2515a9e25bdf72844ba1d3c1510abd833bf3ae6ecd047bd21112746e9836bfc9d6da60616bba644532c44bfe30de90a32
6
+ metadata.gz: e9ad1f070f4c9606ce7608c03d1db0345e290c945706883c04918b99910ab8985dec1505664844f5d2c15cfe6cbed9d7e77700a01d94096df0fb9204ad52555e
7
+ data.tar.gz: 3284db9c4250ac716e4c89cbdde718e5a1d079f97e99ca33925c6a1d537c6a50dd5beb5044af96f61cbd32bce8af6dabea8fdf193e71a480cbab818963ba2e59
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`.
@@ -10,6 +10,7 @@ require_relative '../lib/process_settings/targeted_settings'
10
10
 
11
11
  PROGRAM_NAME = File.basename($PROGRAM_NAME)
12
12
  SETTINGS_FOLDER = 'settings'
13
+ MINIMUM_LIBYAML_VERSION = Gem::Version.new('0.2.6') # So that null (nil) values don't have trailing spaces.
13
14
 
14
15
  def end_marker(version)
15
16
  {
@@ -75,10 +76,29 @@ def add_warning_comment(yaml, root_folder, program_name, settings_folder)
75
76
  yaml.sub("\n", "\n" + warning_comment)
76
77
  end
77
78
 
79
+ def check_libyaml_version
80
+ Gem::Version.new(Psych::LIBYAML_VERSION) >= MINIMUM_LIBYAML_VERSION or
81
+ warn <<~EOS
82
+
83
+ #{PROGRAM_NAME} error: libyaml version #{Psych::LIBYAML_VERSION} must be at least #{MINIMUM_LIBYAML_VERSION}. Try:
84
+
85
+ brew update && upgrade libyaml
86
+
87
+ You may also need:
88
+
89
+ gem install psych -- --enable-bundled-libyaml
90
+ EOS
91
+
92
+ exit(1)
93
+ end
94
+
95
+
78
96
  #
79
97
  # main
80
98
  #
81
99
 
100
+ check_libyaml_version
101
+
82
102
  options = parse_options(ARGV.dup)
83
103
 
84
104
  combined_settings = read_and_combine_settings(Pathname.new(options.root_folder) + SETTINGS_FOLDER)
@@ -29,8 +29,14 @@ module ProcessSettings
29
29
  end
30
30
  deprecate :start, deprecator: ActiveSupport::Deprecation.new('1.0', 'ProcessSettings') # will become private
31
31
 
32
- def enable_listen_thread?(environment)
33
- !disable_listen_thread?
32
+ def listen_thread_running?
33
+ !@listener.nil?
34
+ end
35
+
36
+ private
37
+
38
+ def enable_listen_thread?(environment = nil)
39
+ !disable_listen_thread?(environment)
34
40
  end
35
41
 
36
42
  def disable_listen_thread?(environment = nil)
@@ -40,14 +46,12 @@ module ProcessSettings
40
46
  when 'false', '0'
41
47
  false
42
48
  when nil
43
- environment || service_env == 'test'
49
+ (environment || service_env) == 'test'
44
50
  else
45
51
  raise ArgumentError, "DISABLE_LISTEN_CHANGE_MONITORING has unknown value #{ENV['DISABLE_LISTEN_CHANGE_MONITORING'].inspect}"
46
52
  end
47
53
  end
48
54
 
49
- private
50
-
51
55
  # optionally starts listening for changes, then loads current settings
52
56
  # Note: If with_listen_thread is truthy, this method creates a new thread that will be
53
57
  # monitoring for changes.
@@ -82,6 +86,7 @@ module ProcessSettings
82
86
  # stops listening for changes
83
87
  def stop
84
88
  @listener&.stop
89
+ @listener = nil
85
90
  end
86
91
 
87
92
  def service_env
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ProcessSettings
4
- VERSION = '0.11.0.pre.7'
4
+ VERSION = '0.13.0'
5
5
  end
metadata CHANGED
@@ -1,11 +1,11 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: process_settings
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.11.0.pre.7
4
+ version: 0.13.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Invoca
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
  date: 2019-09-19 00:00:00.000000000 Z
@@ -58,6 +58,20 @@ dependencies:
58
58
  - - "~>"
59
59
  - !ruby/object:Gem::Version
60
60
  version: '3.0'
61
+ - !ruby/object:Gem::Dependency
62
+ name: psych
63
+ requirement: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - "~>"
66
+ - !ruby/object:Gem::Version
67
+ version: '3.2'
68
+ type: :runtime
69
+ prerelease: false
70
+ version_requirements: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - "~>"
73
+ - !ruby/object:Gem::Version
74
+ version: '3.2'
61
75
  description: Targeted process settings that dynamically reload without restarting
62
76
  the process
63
77
  email: development+ps@invoca.com
@@ -97,7 +111,7 @@ licenses:
97
111
  metadata:
98
112
  source_code_uri: https://github.com/Invoca/process_settings
99
113
  allowed_push_host: https://rubygems.org
100
- post_install_message:
114
+ post_install_message:
101
115
  rdoc_options: []
102
116
  require_paths:
103
117
  - lib
@@ -108,12 +122,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
108
122
  version: '0'
109
123
  required_rubygems_version: !ruby/object:Gem::Requirement
110
124
  requirements:
111
- - - ">"
125
+ - - ">="
112
126
  - !ruby/object:Gem::Version
113
- version: 1.3.1
127
+ version: '0'
114
128
  requirements: []
115
129
  rubygems_version: 3.0.3
116
- signing_key:
130
+ signing_key:
117
131
  specification_version: 4
118
132
  summary: Dynamic process settings
119
133
  test_files: []