unicorn_wrangler 0.4.0 → 0.5.0
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 +5 -5
- data/lib/unicorn_wrangler.rb +39 -0
- data/lib/unicorn_wrangler/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 19c14c7fa55054a95ced0309e7572bd3917d518bd9906a7775adee3423d82b79
|
4
|
+
data.tar.gz: 0326a1740dd4a9b76ba21cd8e4bd45e11aed7a9109eb7a837948f70736104bed
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d6669d17513fc1eebcf1e7721bf331ce38c37ac145b2f66ea4622df50a1823673ce88bdd8092024d60caf88c543faea48a133a2dda108da60b5fb5094d7218a6
|
7
|
+
data.tar.gz: c5b1211ac5758cf840a7a63628095be835b5c409b1ce7660e1b5c399a65b6a58db342c01ac91c6a7cb8dc270d94a1c401921928bbe30765626fbc36216e36fcc
|
data/lib/unicorn_wrangler.rb
CHANGED
@@ -17,6 +17,7 @@ module UnicornWrangler
|
|
17
17
|
kill_after_requests: 10000,
|
18
18
|
gc_after_request_time: 10,
|
19
19
|
kill_on_too_much_memory: {},
|
20
|
+
map_term_to_quit: false,
|
20
21
|
logger:,
|
21
22
|
stats: nil # provide a statsd client with your apps namespace to collect stats
|
22
23
|
)
|
@@ -25,6 +26,27 @@ module UnicornWrangler
|
|
25
26
|
@handlers << RequestKiller.new(logger, stats, kill_after_requests) if kill_after_requests
|
26
27
|
@handlers << OutOfMemoryKiller.new(logger, stats, kill_on_too_much_memory) if kill_on_too_much_memory
|
27
28
|
@handlers << OutOfBandGC.new(logger, stats, gc_after_request_time) if gc_after_request_time
|
29
|
+
|
30
|
+
@hooks = {}
|
31
|
+
if map_term_to_quit
|
32
|
+
# - on heroku & kubernetes all processes get TERM, so we need to trap in master and worker
|
33
|
+
# - trapping has to be done in the before_fork since unicorn sets up it's own traps on start
|
34
|
+
# - we cannot write to logger inside of a trap, so need to spawn a new Thread
|
35
|
+
# - manual test: add a slow route + rails s + curl + pkill -TERM -f 'unicorn master' - request finished?
|
36
|
+
@hooks[:before_fork] = -> do
|
37
|
+
Signal.trap :TERM do
|
38
|
+
Thread.new { logger.info 'master intercepting TERM and sending myself QUIT instead' }
|
39
|
+
Process.kill :QUIT, Process.pid
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
@hooks[:after_fork] = ->(*) do
|
44
|
+
Signal.trap :TERM do
|
45
|
+
Thread.new { logger.info 'worker intercepting TERM and doing nothing. Wait for master to send QUIT' }
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
28
50
|
Unicorn::HttpServer.prepend UnicornExtension
|
29
51
|
end
|
30
52
|
|
@@ -39,9 +61,26 @@ module UnicornWrangler
|
|
39
61
|
ensure
|
40
62
|
@handlers.each { |handler| handler.call(@requests, @request_time) }
|
41
63
|
end
|
64
|
+
|
65
|
+
def perform_hook(name)
|
66
|
+
if hook = @hooks[name]
|
67
|
+
hook.call
|
68
|
+
end
|
69
|
+
end
|
42
70
|
end
|
43
71
|
|
44
72
|
module UnicornExtension
|
73
|
+
# call our hook and the users hook since only a single hook can be configured at a time
|
74
|
+
# we need to call super so the @<hook> variables get set and unset properly in after_fork to not leak memory
|
75
|
+
[:after_fork, :before_fork].each do |hook|
|
76
|
+
define_method("#{hook}=") do |value|
|
77
|
+
super(->(*args) do
|
78
|
+
UnicornWrangler.perform_hook(hook)
|
79
|
+
value.call(*args)
|
80
|
+
end)
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
45
84
|
def process_client(*)
|
46
85
|
UnicornWrangler.perform_request { super }
|
47
86
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: unicorn_wrangler
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Michael Grosser
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2018-04-18 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description:
|
14
14
|
email: michael@grosser.it
|
@@ -39,7 +39,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
39
39
|
version: '0'
|
40
40
|
requirements: []
|
41
41
|
rubyforge_project:
|
42
|
-
rubygems_version: 2.
|
42
|
+
rubygems_version: 2.7.6
|
43
43
|
signing_key:
|
44
44
|
specification_version: 4
|
45
45
|
summary: 'Unicorn: out of band GC / restart on max memory bloat / restart after X
|