etcenv 0.5.4 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/etcenv/environment.rb +9 -2
- data/lib/etcenv/version.rb +1 -1
- data/lib/etcenv/watcher.rb +37 -4
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 71bb85e40d0ef6634a604310ebe76b3a7707244e
|
4
|
+
data.tar.gz: 4bfeab28a6562cc8fb7e259cafccc92396a3d198
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5837fa617120b09edf6fa744bf93d48e499bd4fd90aa4537a761c409ded2c804a4bb7142fe00ef495c59a2bd11d5814c7e54fad61994e3f083f5e51a20689841
|
7
|
+
data.tar.gz: 6968faa4d765dca8c58097adfdbf1d395133018f0075e22e4f9d898b1c8de8ca06ea2a69355e79f683c3076b0b3b6ab29e8df60db09164e107dfb43a0fa008ee
|
data/lib/etcenv/environment.rb
CHANGED
@@ -21,7 +21,7 @@ module Etcenv
|
|
21
21
|
load
|
22
22
|
end
|
23
23
|
|
24
|
-
attr_reader :root_key, :env, :etcd
|
24
|
+
attr_reader :root_key, :env, :etcd, :cluster_index
|
25
25
|
attr_accessor :max_depth
|
26
26
|
|
27
27
|
def expanded_env
|
@@ -32,6 +32,10 @@ module Etcenv
|
|
32
32
|
@modified_indices ||= {}
|
33
33
|
end
|
34
34
|
|
35
|
+
def keys
|
36
|
+
modified_indices.keys
|
37
|
+
end
|
38
|
+
|
35
39
|
def load
|
36
40
|
@lock.synchronize do
|
37
41
|
flush
|
@@ -52,6 +56,7 @@ module Etcenv
|
|
52
56
|
@includes = nil
|
53
57
|
@cache = {}
|
54
58
|
@modified_indices = {}
|
59
|
+
@cluster_index = nil
|
55
60
|
self
|
56
61
|
end
|
57
62
|
|
@@ -79,7 +84,9 @@ module Etcenv
|
|
79
84
|
key = resolve_key(name)
|
80
85
|
return cache[key] if cache[key]
|
81
86
|
|
82
|
-
|
87
|
+
resp = @etcd.get(key)
|
88
|
+
node = resp.node
|
89
|
+
@cluster_index = [@cluster_index, resp.etcd_index].compact.min
|
83
90
|
|
84
91
|
if node.etcvault_error
|
85
92
|
raise EtcvaultFailure, node.etcvault_error
|
data/lib/etcenv/version.rb
CHANGED
data/lib/etcenv/watcher.rb
CHANGED
@@ -19,8 +19,8 @@ module Etcenv
|
|
19
19
|
|
20
20
|
def watch
|
21
21
|
ch = Queue.new
|
22
|
-
threads = env.
|
23
|
-
Thread.new(ch, key,
|
22
|
+
threads = env.keys.map do |key|
|
23
|
+
Thread.new(ch, key, env.cluster_index, &method(:watch_thread)).tap do |th|
|
24
24
|
th.abort_on_exception = true
|
25
25
|
end
|
26
26
|
end
|
@@ -30,6 +30,7 @@ module Etcenv
|
|
30
30
|
end
|
31
31
|
|
32
32
|
def auto_reload_loop
|
33
|
+
retries = 0
|
33
34
|
loop do
|
34
35
|
begin
|
35
36
|
watch
|
@@ -37,8 +38,15 @@ module Etcenv
|
|
37
38
|
env.load
|
38
39
|
yield env if block_given?
|
39
40
|
rescue => e
|
41
|
+
retries += 1
|
42
|
+
interval = (2**retries) * 0.1
|
43
|
+
|
40
44
|
$stderr.puts "[watcher][error] Failed to reload env #{env.root_key}: #{e.inspect}"
|
41
45
|
$stderr.puts "\t#{e.backtrace.join("\n\t")}"
|
46
|
+
$stderr.puts "[watcher][error] RETRYING reload #{env.root_key} in #{'%.2f' % interval} sec"
|
47
|
+
sleep interval
|
48
|
+
else
|
49
|
+
retries = 0
|
42
50
|
end
|
43
51
|
end
|
44
52
|
end
|
@@ -46,8 +54,24 @@ module Etcenv
|
|
46
54
|
private
|
47
55
|
|
48
56
|
def watch_thread(ch, key, index)
|
57
|
+
tries = 0
|
58
|
+
loop do
|
59
|
+
if try_watch(key, index)
|
60
|
+
ch << key
|
61
|
+
break
|
62
|
+
end
|
63
|
+
interval = (2 ** tries) * 0.1
|
64
|
+
$stderr.puts "[watcher] RETRYING; #{key.inspect} watch will resume after #{'%.2f' % interval} sec"
|
65
|
+
sleep interval
|
66
|
+
tries += 1
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
def try_watch(key, index)
|
49
71
|
$stderr.puts "[watcher] waiting for change on #{key} (index: #{index.succ})" if verbose
|
50
|
-
|
72
|
+
index = [@indices[key], index].compact.max
|
73
|
+
index += 1 if index
|
74
|
+
response = etcd.watch(key, recursive: true, index: index, timeout: WATCH_TIMEOUT)
|
51
75
|
@lock.synchronize do
|
52
76
|
# Record modified_index in watcher itself; Because the latest index may be hidden in normal response
|
53
77
|
# e.g. unlisted keys, removed keys
|
@@ -55,8 +79,17 @@ module Etcenv
|
|
55
79
|
end
|
56
80
|
$stderr.puts "[watcher] dir #{key} has updated" if verbose
|
57
81
|
ch << key
|
82
|
+
return true
|
83
|
+
rescue Etcd::EventIndexCleared => e
|
84
|
+
$stderr.puts "[watcher][warn] #{e.inspect} on key #{key.inspect}, trying to get X-Etcd-Index" if verbose
|
85
|
+
@lock.synchronize do
|
86
|
+
@indices[key] = etcd.get(key).etcd_index
|
87
|
+
end
|
88
|
+
$stderr.puts "[watcher][warn] Updated #{key.inspect} index to #{@indices[key]}" if verbose
|
89
|
+
return nil
|
58
90
|
rescue Net::ReadTimeout
|
59
|
-
|
91
|
+
$stderr.puts "[watcher] #{e.inspect} on key #{key.inspect}" if verbose
|
92
|
+
return nil
|
60
93
|
end
|
61
94
|
end
|
62
95
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: etcenv
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Shota Fukumori (sora_h)
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2016-05-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -128,7 +128,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
128
128
|
version: '0'
|
129
129
|
requirements: []
|
130
130
|
rubyforge_project:
|
131
|
-
rubygems_version: 2.
|
131
|
+
rubygems_version: 2.6.3
|
132
132
|
signing_key:
|
133
133
|
specification_version: 4
|
134
134
|
summary: Dump etcd keys into dotenv file or docker env file
|