brainzlab 0.1.25 → 0.1.26
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 +4 -4
- data/lib/brainzlab/flux/buffer.rb +19 -1
- data/lib/brainzlab/flux.rb +11 -1
- data/lib/brainzlab/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: e298648a456d207e9ec5eb9be700b6aa898fc9b77666a3afd3c737d9c126705e
|
|
4
|
+
data.tar.gz: b87707b7eb15cfb9dd11ca461203d0ccd1a7199bdd0ce972327381ecb675d592
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: f834d99194f33b06a00f18016879e83fefcd92b5ac4bd589804a7629a2b123699ecf58082923920a72384502dacc1e40ced04ccfb2b36ec2cf6c2791adab2e3a
|
|
7
|
+
data.tar.gz: 3999f40f6af0bb7b952baf59a35c78acbb38f89e41638824c86dc38a0319f0d964911fd3bc096bba272738c5bc1190777ce98a633a6050f9b7103b59ef8f13c7
|
|
@@ -13,8 +13,10 @@ module BrainzLab
|
|
|
13
13
|
@metrics = []
|
|
14
14
|
@mutex = Mutex.new
|
|
15
15
|
@last_flush = Time.now
|
|
16
|
+
@shutdown = false
|
|
16
17
|
|
|
17
18
|
start_flush_thread
|
|
19
|
+
setup_at_exit
|
|
18
20
|
end
|
|
19
21
|
|
|
20
22
|
def add(type, data)
|
|
@@ -80,8 +82,10 @@ module BrainzLab
|
|
|
80
82
|
end
|
|
81
83
|
|
|
82
84
|
def start_flush_thread
|
|
83
|
-
Thread.new do
|
|
85
|
+
@flush_thread = Thread.new do
|
|
84
86
|
loop do
|
|
87
|
+
break if @shutdown
|
|
88
|
+
|
|
85
89
|
sleep FLUSH_INTERVAL
|
|
86
90
|
begin
|
|
87
91
|
flush! if size.positive?
|
|
@@ -90,6 +94,20 @@ module BrainzLab
|
|
|
90
94
|
end
|
|
91
95
|
end
|
|
92
96
|
end
|
|
97
|
+
@flush_thread.abort_on_exception = false
|
|
98
|
+
end
|
|
99
|
+
|
|
100
|
+
# Flush whatever is buffered when the process exits (SIGTERM on deploy,
|
|
101
|
+
# graceful Puma worker shutdown) so the last batch isn't lost.
|
|
102
|
+
def setup_at_exit
|
|
103
|
+
at_exit do
|
|
104
|
+
@shutdown = true
|
|
105
|
+
begin
|
|
106
|
+
flush! if size.positive?
|
|
107
|
+
rescue StandardError
|
|
108
|
+
nil
|
|
109
|
+
end
|
|
110
|
+
end
|
|
93
111
|
end
|
|
94
112
|
end
|
|
95
113
|
end
|
data/lib/brainzlab/flux.rb
CHANGED
|
@@ -164,12 +164,22 @@ module BrainzLab
|
|
|
164
164
|
end
|
|
165
165
|
|
|
166
166
|
def buffer
|
|
167
|
-
|
|
167
|
+
# Fork-safety: the buffer owns a background flush thread that does NOT
|
|
168
|
+
# survive a fork (e.g. Puma workers). If we're now in a different
|
|
169
|
+
# process than the one that created the buffer, recreate it so each
|
|
170
|
+
# worker gets a live flush thread — otherwise web-emitted events/metrics
|
|
171
|
+
# buffer forever in the worker and never get sent.
|
|
172
|
+
if @buffer.nil? || @buffer_pid != Process.pid
|
|
173
|
+
@buffer = Buffer.new(client)
|
|
174
|
+
@buffer_pid = Process.pid
|
|
175
|
+
end
|
|
176
|
+
@buffer
|
|
168
177
|
end
|
|
169
178
|
|
|
170
179
|
def reset!
|
|
171
180
|
@client = nil
|
|
172
181
|
@buffer = nil
|
|
182
|
+
@buffer_pid = nil
|
|
173
183
|
@provisioner = nil
|
|
174
184
|
@provisioned = false
|
|
175
185
|
end
|
data/lib/brainzlab/version.rb
CHANGED