dmexe-thrifty 0.1.0 → 0.1.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 +4 -4
- data/lib/thrifty/http_server/log_middleware.rb +2 -2
- data/lib/thrifty/http_server/puma_server.rb +1 -1
- data/lib/thrifty/hutch/builder.rb +9 -1
- data/lib/thrifty/logger/app.rb +13 -2
- data/lib/thrifty/signals.rb +30 -8
- data/lib/thrifty/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fa08531660b09078cd5a18d94337dfde405914de
|
4
|
+
data.tar.gz: 439df8156f3d1f8ff52d7819b93a9153ef20f3d3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4469b31c70a71b98c0027b5df2a65faef492c500f220b3f789c8837f461ada1d098ac8fdffe3ca39cc7fa0300668cb9984f6d42739783d9c1014bad74826bdad
|
7
|
+
data.tar.gz: c42ae1a28b8bb5c6ecd43b8cd31051a033204a45cfad3e1fdf21af207e9eb6f85df2ccee7347a17f5619cfbbeae4332248fc808dda6fb4b6f02451033416a745
|
@@ -24,12 +24,12 @@ module Thrifty::HTTP::Server
|
|
24
24
|
peer = env['HTTP_X_FORWARDED_FOR'] || env["REMOTE_ADDR"]
|
25
25
|
|
26
26
|
payload = {
|
27
|
-
peer: peer,
|
28
|
-
status: status.to_s[0..3],
|
29
27
|
method: env[Rack::REQUEST_METHOD],
|
30
28
|
path: env[Rack::PATH_INFO],
|
31
29
|
query: env[Rack::QUERY_STRING],
|
30
|
+
status: status.to_s[0..3],
|
32
31
|
len: length,
|
32
|
+
peer: peer,
|
33
33
|
duration: now - began_at
|
34
34
|
}
|
35
35
|
|
@@ -15,7 +15,7 @@ module Thrifty::HTTP::Server
|
|
15
15
|
ip = options[:ip] || DEFAULT_IP
|
16
16
|
min = options[:min] || DEFAULT_MIN_TH
|
17
17
|
max = options[:max] || DEFAULT_MAX_TH
|
18
|
-
name = options[:name] ||
|
18
|
+
name = options[:name] || "Thrifty::HTTP::Server"
|
19
19
|
|
20
20
|
@log = Thrifty.get_logger(name)
|
21
21
|
@bind = "#{ip}:#{port}"
|
@@ -5,7 +5,8 @@ module Thrifty::Hutch
|
|
5
5
|
def initialize
|
6
6
|
require 'hutch'
|
7
7
|
|
8
|
-
@url
|
8
|
+
@url = ENV['RABBITMQ_URL'] || 'amqp://guest:guest@localhost:5672/'
|
9
|
+
@exchange = 'hutch'
|
9
10
|
|
10
11
|
@lock = Mutex.new
|
11
12
|
|
@@ -19,6 +20,11 @@ module Thrifty::Hutch
|
|
19
20
|
self
|
20
21
|
end
|
21
22
|
|
23
|
+
def with_exchange(name)
|
24
|
+
::Hutch::Config.set(:mq_exchange, name)
|
25
|
+
self
|
26
|
+
end
|
27
|
+
|
22
28
|
def build
|
23
29
|
::Hutch::Logging.logger = Thrifty.get_logger "Hutch"
|
24
30
|
::Hutch::Config.set(:uri, @url)
|
@@ -30,8 +36,10 @@ module Thrifty::Hutch
|
|
30
36
|
def stop
|
31
37
|
@lock.synchronize do
|
32
38
|
if @worker
|
39
|
+
::Hutch::Logging.logger.info "stopping"
|
33
40
|
@worker.stop
|
34
41
|
::Hutch.disconnect
|
42
|
+
::Hutch::Logging.logger.info "stopped"
|
35
43
|
@worker = nil
|
36
44
|
end
|
37
45
|
end
|
data/lib/thrifty/logger/app.rb
CHANGED
@@ -10,7 +10,7 @@ module Thrifty::Logger
|
|
10
10
|
@queue = Queue.new
|
11
11
|
@lock = Mutex.new
|
12
12
|
|
13
|
-
Thrifty::Signals.
|
13
|
+
Thrifty::Signals.register_after(method(:stop))
|
14
14
|
end
|
15
15
|
|
16
16
|
def start
|
@@ -28,9 +28,11 @@ module Thrifty::Logger
|
|
28
28
|
def stop
|
29
29
|
@lock.synchronize do
|
30
30
|
return unless @thread
|
31
|
-
|
31
|
+
append(new_entry("stopping"))
|
32
|
+
append(:shutdown)
|
32
33
|
@thread.join
|
33
34
|
@thread = nil
|
35
|
+
App.append(new_entry("stopped"))
|
34
36
|
end
|
35
37
|
end
|
36
38
|
|
@@ -40,6 +42,15 @@ module Thrifty::Logger
|
|
40
42
|
|
41
43
|
private
|
42
44
|
|
45
|
+
def new_entry(msg)
|
46
|
+
Entry.new(
|
47
|
+
:info,
|
48
|
+
Time.now,
|
49
|
+
self.class,
|
50
|
+
msg
|
51
|
+
)
|
52
|
+
end
|
53
|
+
|
43
54
|
def main_loop ; Thread.new do
|
44
55
|
begin
|
45
56
|
loop do
|
data/lib/thrifty/signals.rb
CHANGED
@@ -7,25 +7,42 @@ module Thrifty ; class Signals
|
|
7
7
|
|
8
8
|
class << self
|
9
9
|
def register(fn)
|
10
|
+
instance.install
|
10
11
|
instance.register(fn)
|
11
12
|
end
|
13
|
+
|
14
|
+
def register_after(fn)
|
15
|
+
instance.install
|
16
|
+
instance.register_after(fn)
|
17
|
+
end
|
12
18
|
end
|
13
19
|
|
14
20
|
def initialize
|
15
|
-
@handlers
|
16
|
-
@
|
17
|
-
@
|
21
|
+
@handlers = []
|
22
|
+
@after = []
|
23
|
+
@mutex = Mutex.new
|
24
|
+
@resource = ConditionVariable.new
|
25
|
+
@installed = false
|
18
26
|
end
|
19
27
|
|
20
28
|
def install
|
21
|
-
|
22
|
-
|
29
|
+
unless @installed
|
30
|
+
%w{INT TERM}.each do |sig|
|
31
|
+
trap sig do
|
32
|
+
Thread.new{ shutdown }.join
|
33
|
+
end
|
34
|
+
end
|
35
|
+
@installed = true
|
23
36
|
end
|
24
37
|
end
|
25
38
|
|
26
39
|
def wait
|
27
|
-
|
28
|
-
@
|
40
|
+
begin
|
41
|
+
@mutex.synchronize do
|
42
|
+
@resource.wait(@mutex)
|
43
|
+
end
|
44
|
+
rescue ::Interrupt
|
45
|
+
shutdown
|
29
46
|
end
|
30
47
|
end
|
31
48
|
|
@@ -33,8 +50,13 @@ module Thrifty ; class Signals
|
|
33
50
|
@handlers << fn
|
34
51
|
end
|
35
52
|
|
36
|
-
def
|
53
|
+
def register_after(fn)
|
54
|
+
@after << fn
|
55
|
+
end
|
56
|
+
|
57
|
+
def shutdown(sig = nil)
|
37
58
|
@handlers.each {|fn| fn.call }
|
59
|
+
@after.each {|fn| fn.call }
|
38
60
|
|
39
61
|
@mutex.synchronize do
|
40
62
|
@resource.signal
|
data/lib/thrifty/version.rb
CHANGED