enviroblyd 0.4.6 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/enviroblyd +9 -1
- data/lib/enviroblyd/daemon.rb +24 -16
- data/lib/enviroblyd/version.rb +1 -1
- data/lib/enviroblyd/web.rb +3 -3
- 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: 329d9e7586d58e8b529d2a94d46be76130efb24bf688a4d53efe17dfeaf3e7e0
|
4
|
+
data.tar.gz: 47cf08b7ecf7231460aeed688aa76705abff6cdcfdf770148f9f86f378ee513e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f57916ca0d0615cd05cffcf15527f506a8ca60a47cec03f5d9ea4262b4ce0b298ae764cace907c764c4de9307f870659657610629c98e7ebd8d8c81388000623
|
7
|
+
data.tar.gz: a260266cb641e0b7e99d2e35f21cde3fcd82f80570782ce5628c4081c4e6f9773ee35ea4d660514267407ccc000146b3db1b504b60370518653f2b61c13ba719
|
data/bin/enviroblyd
CHANGED
data/lib/enviroblyd/daemon.rb
CHANGED
@@ -6,29 +6,25 @@ class Enviroblyd::Daemon
|
|
6
6
|
MAX_MESSAGE_SIZE = 6000 # bytes
|
7
7
|
PORT = ENV.fetch("ENVIROBLYD_PORT", 63106).to_i
|
8
8
|
|
9
|
-
def
|
9
|
+
def initialize
|
10
10
|
imds = Enviroblyd::IMDS.new
|
11
|
-
host = imds.private_ipv4
|
12
|
-
|
13
|
-
|
14
|
-
end
|
15
|
-
|
16
|
-
def initialize(host)
|
17
|
-
@host = host
|
11
|
+
@host = imds.private_ipv4
|
12
|
+
@threads = []
|
13
|
+
@shutdown = false
|
18
14
|
end
|
19
15
|
|
20
16
|
def listen
|
21
|
-
server = TCPServer.new @host, PORT
|
17
|
+
@server = TCPServer.new @host, PORT
|
22
18
|
puts "Listening on #{@host}:#{PORT}"
|
23
19
|
Enviroblyd::Web.register
|
24
20
|
|
25
|
-
|
26
|
-
Thread.start(server.accept) do |client|
|
21
|
+
until @shutdown do
|
22
|
+
@threads << Thread.start(@server.accept) do |client|
|
27
23
|
message = client.recv(MAX_MESSAGE_SIZE)
|
28
24
|
command = Enviroblyd::Command.new message
|
29
25
|
|
30
26
|
unless command.valid?
|
31
|
-
|
27
|
+
puts "Invalid message received: #{message}"
|
32
28
|
client.puts "Invalid message"
|
33
29
|
next
|
34
30
|
end
|
@@ -38,11 +34,23 @@ class Enviroblyd::Daemon
|
|
38
34
|
command.run
|
39
35
|
ensure
|
40
36
|
client.close
|
41
|
-
command = nil
|
42
|
-
message = nil
|
43
|
-
client = nil
|
44
|
-
GC.start
|
45
37
|
end
|
38
|
+
|
39
|
+
delete_dead_threads
|
40
|
+
GC.start
|
41
|
+
GC.compact
|
46
42
|
end
|
47
43
|
end
|
44
|
+
|
45
|
+
def shutdown
|
46
|
+
@threads.each(&:join)
|
47
|
+
end
|
48
|
+
|
49
|
+
private
|
50
|
+
def delete_dead_threads
|
51
|
+
@threads.each do |thread|
|
52
|
+
next if thread.alive?
|
53
|
+
@threads.delete thread
|
54
|
+
end
|
55
|
+
end
|
48
56
|
end
|
data/lib/enviroblyd/version.rb
CHANGED
data/lib/enviroblyd/web.rb
CHANGED
@@ -33,8 +33,8 @@ class Enviroblyd::Web
|
|
33
33
|
|
34
34
|
def http(url, type: Net::HTTP::Get, params: nil, headers: {}, retry_interval: 3, retries: 10, backoff: :exponential, tries: 1)
|
35
35
|
if retries <= tries
|
36
|
-
|
37
|
-
|
36
|
+
puts "Retried #{url} #{tries} times. Aborting."
|
37
|
+
return
|
38
38
|
end
|
39
39
|
|
40
40
|
uri = URI(url)
|
@@ -56,7 +56,7 @@ class Enviroblyd::Web
|
|
56
56
|
|
57
57
|
if response == :retry || (500..599).include?(response.code.to_i)
|
58
58
|
sleep_time = (backoff == :exponential) ? (retry_interval * tries) : retry_interval
|
59
|
-
|
59
|
+
puts "Retry #{uri} in #{sleep_time}s"
|
60
60
|
sleep sleep_time
|
61
61
|
http(url, type:, params:, retry_interval:, retries:, backoff:, tries: (tries + 1))
|
62
62
|
else
|