macaw_framework 1.0.4 → 1.0.5
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/CHANGELOG.md +4 -0
- data/lib/macaw_framework/core/server.rb +38 -7
- data/lib/macaw_framework/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 8f108da6fb2654c701154a544cea00e47d9546c5092ef3dcbc1e299c34420ddd
|
|
4
|
+
data.tar.gz: 23c72078365336da0585d7ee88cce41db2972efcfcc72c930ccceb73edb302ed
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 9e0feab01f25bab3ce8b65799c516f04a837c5e250b8f53934049c2c3f1db303d92cfa9629151c0c8b46836e9a77690aea1a27cfc7b8bb1b99c7f9340a3cb8f1
|
|
7
|
+
data.tar.gz: cb769896b94e443248ecc419ffb69f0c587e9cda52430516204b8bcfed0a56eed5cf4aac3f6ca05f53dabe5d954777579e088c351dd82f2a61fdf47871bc143a
|
data/CHANGELOG.md
CHANGED
|
@@ -55,14 +55,15 @@ class Server
|
|
|
55
55
|
def run
|
|
56
56
|
@server = TCPServer.new(@bind, @port)
|
|
57
57
|
@server = OpenSSL::SSL::SSLServer.new(@server, @context) if @context
|
|
58
|
+
@workers_mutex = Mutex.new
|
|
58
59
|
@num_threads.times do
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
client = @work_queue.pop
|
|
62
|
-
break if client == :shutdown
|
|
60
|
+
spawn_worker
|
|
61
|
+
end
|
|
63
62
|
|
|
64
|
-
|
|
65
|
-
|
|
63
|
+
Thread.new do
|
|
64
|
+
loop do
|
|
65
|
+
sleep 10
|
|
66
|
+
maintain_worker_pool
|
|
66
67
|
end
|
|
67
68
|
end
|
|
68
69
|
|
|
@@ -100,6 +101,8 @@ class Server
|
|
|
100
101
|
message ||= nil
|
|
101
102
|
response_headers ||= nil
|
|
102
103
|
client.puts ResponseDataFilter.mount_response(status, response_headers, message)
|
|
104
|
+
rescue IOError, Errno::EPIPE => e
|
|
105
|
+
@macaw_log.error("Error writing to client: #{e.message}")
|
|
103
106
|
rescue TooManyRequestsError
|
|
104
107
|
client.print "HTTP/1.1 429 Too Many Requests\r\n\r\n"
|
|
105
108
|
rescue EndpointNotMappedError
|
|
@@ -108,7 +111,11 @@ class Server
|
|
|
108
111
|
client.print "HTTP/1.1 500 Internal Server Error\r\n\r\n"
|
|
109
112
|
@macaw_log.info("Error: #{e}")
|
|
110
113
|
ensure
|
|
111
|
-
|
|
114
|
+
begin
|
|
115
|
+
client.close
|
|
116
|
+
rescue IOError => e
|
|
117
|
+
@macaw_log.error("Error closing client: #{e.message}")
|
|
118
|
+
end
|
|
112
119
|
end
|
|
113
120
|
|
|
114
121
|
def declare_client_session(client)
|
|
@@ -181,4 +188,28 @@ class Server
|
|
|
181
188
|
def get_client_data(body, headers, parameters)
|
|
182
189
|
{ body: body, headers: headers, params: parameters }
|
|
183
190
|
end
|
|
191
|
+
|
|
192
|
+
def spawn_worker
|
|
193
|
+
@workers_mutex.synchronize do
|
|
194
|
+
@workers << Thread.new do
|
|
195
|
+
loop do
|
|
196
|
+
client = @work_queue.pop
|
|
197
|
+
break if client == :shutdown
|
|
198
|
+
|
|
199
|
+
handle_client(client)
|
|
200
|
+
end
|
|
201
|
+
end
|
|
202
|
+
end
|
|
203
|
+
end
|
|
204
|
+
|
|
205
|
+
def maintain_worker_pool
|
|
206
|
+
@workers_mutex.synchronize do
|
|
207
|
+
@workers.each_with_index do |worker, index|
|
|
208
|
+
unless worker.alive?
|
|
209
|
+
@macaw_log.error("Worker thread #{index} died, respawning...")
|
|
210
|
+
@workers[index] = spawn_worker
|
|
211
|
+
end
|
|
212
|
+
end
|
|
213
|
+
end
|
|
214
|
+
end
|
|
184
215
|
end
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: macaw_framework
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.0.
|
|
4
|
+
version: 1.0.5
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Aria Diniz
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2023-05-
|
|
11
|
+
date: 2023-05-12 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: prometheus-client
|