rubypitaya 1.3.1 → 1.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/rubypitaya/app-template/Gemfile +1 -1
- data/lib/rubypitaya/app-template/Gemfile.lock +2 -2
- data/lib/rubypitaya/app-template/docker-compose.yml +1 -0
- data/lib/rubypitaya/core/etcd_connector.rb +41 -5
- data/lib/rubypitaya/core/main.rb +3 -1
- data/lib/rubypitaya/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: 3fe7572b5e800053db6b8d837220cd94b1fbe34c3d7b31b712bd009adc81cfa0
|
4
|
+
data.tar.gz: 5d9b2a19b1f7884982755de17477c74703da673a570c826dcf34dda450b58db1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4b840698bd22dcca93067960b568e836bf586d6cb1e25289ad16d432161380f85bd087728edfc4678f68daf41e73ca63ea7a51db4ee79169db60a68c7862aa1d
|
7
|
+
data.tar.gz: 0af3191c1ac731265e3e8f16d085bdcea0c144865cb2b4a2239a5a27a7f5adcd264679cc79045abfcbe40420a75086d592dd6f7b529d55ff7052c087b954bf58
|
@@ -62,7 +62,7 @@ GEM
|
|
62
62
|
diff-lcs (>= 1.2.0, < 2.0)
|
63
63
|
rspec-support (~> 3.8.0)
|
64
64
|
rspec-support (3.8.3)
|
65
|
-
rubypitaya (1.
|
65
|
+
rubypitaya (1.4.0)
|
66
66
|
activerecord (= 6.0.2)
|
67
67
|
etcdv3 (= 0.10.2)
|
68
68
|
eventmachine (= 1.2.7)
|
@@ -85,7 +85,7 @@ DEPENDENCIES
|
|
85
85
|
pry (= 0.12.2)
|
86
86
|
rake (= 10.0)
|
87
87
|
rspec (= 3.8.0)
|
88
|
-
rubypitaya (= 1.
|
88
|
+
rubypitaya (= 1.4.0)
|
89
89
|
|
90
90
|
BUNDLED WITH
|
91
91
|
1.17.2
|
@@ -6,35 +6,71 @@ module RubyPitaya
|
|
6
6
|
class EtcdConnector
|
7
7
|
|
8
8
|
def initialize(server_uuid, desktop_name, server_name, etcd_prefix,
|
9
|
-
|
9
|
+
etcd_address, allow_reconnect, lease_seconds)
|
10
10
|
@server_uuid = server_uuid
|
11
11
|
@server_name = server_name
|
12
12
|
@desktop_name = desktop_name
|
13
13
|
@etcd_prefix = etcd_prefix
|
14
14
|
@etcd_address = etcd_address
|
15
15
|
@allow_reconnect = allow_reconnect
|
16
|
+
@lease_seconds = lease_seconds
|
17
|
+
|
18
|
+
@renew_connection_seconds = lease_seconds / 2.0
|
19
|
+
|
20
|
+
@renew_connection_key = nil
|
21
|
+
@renew_connection_value = nil
|
22
|
+
@renew_connection_thread = nil
|
16
23
|
end
|
17
24
|
|
18
25
|
def connect
|
26
|
+
connection_key = get_connection_key
|
27
|
+
connection_value = get_connection_value
|
28
|
+
|
19
29
|
@connection = Etcdv3.new(endpoints: @etcd_address,
|
20
30
|
allow_reconnect: @allow_reconnect)
|
21
|
-
|
31
|
+
|
32
|
+
@lease = @connection.lease_grant(@lease_seconds)
|
33
|
+
|
34
|
+
@connection.put(connection_key, connection_value, lease: @lease.ID)
|
35
|
+
|
36
|
+
@renew_connection_key = connection_key
|
37
|
+
@renew_connection_value = connection_value
|
38
|
+
|
39
|
+
renew_connection
|
22
40
|
end
|
23
41
|
|
24
42
|
def disconnect
|
25
|
-
@connection.del(
|
43
|
+
@connection.del(get_connection_key)
|
26
44
|
end
|
27
45
|
|
28
46
|
private
|
29
47
|
|
30
|
-
def
|
48
|
+
def get_connection_key
|
31
49
|
"#{@etcd_prefix}servers/#{@server_name}/#{@server_uuid}"
|
32
50
|
end
|
33
51
|
|
34
|
-
def
|
52
|
+
def get_connection_value
|
35
53
|
JSON.generate(get_server_data)
|
36
54
|
end
|
37
55
|
|
56
|
+
def renew_connection
|
57
|
+
stop_renew_connection
|
58
|
+
|
59
|
+
@renew_connection_thread = Thread.new do
|
60
|
+
loop do
|
61
|
+
sleep(@renew_connection_seconds)
|
62
|
+
|
63
|
+
@lease = @connection.lease_grant(@lease_seconds)
|
64
|
+
@connection.put(@renew_connection_key, @renew_connection_value,
|
65
|
+
lease: @lease.ID)
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
def stop_renew_connection
|
71
|
+
@renew_connection_thread.exit unless @renew_connection_thread.nil?
|
72
|
+
end
|
73
|
+
|
38
74
|
def get_server_data
|
39
75
|
{
|
40
76
|
id: @server_uuid,
|
data/lib/rubypitaya/core/main.rb
CHANGED
@@ -38,10 +38,12 @@ module RubyPitaya
|
|
38
38
|
|
39
39
|
@etcd_prefix = ENV['ETCD_PREFIX']
|
40
40
|
@etcd_address = ENV['ETCD_URL']
|
41
|
+
@etcd_lease_seconds = ENV['ETCD_LEASE_SECONDS'].to_i
|
41
42
|
@allow_reconnect = false
|
42
43
|
@etcd_connector = EtcdConnector.new(@service_uuid, @desktop_name,
|
43
44
|
@server_name, @etcd_prefix,
|
44
|
-
@etcd_address, @allow_reconnect
|
45
|
+
@etcd_address, @allow_reconnect,
|
46
|
+
@etcd_lease_seconds)
|
45
47
|
@etcd_connector.connect
|
46
48
|
|
47
49
|
@nats_address = ENV['NATS_URL']
|
data/lib/rubypitaya/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rubypitaya
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Luciano Prestes Cavalcanti
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-05-
|
11
|
+
date: 2020-05-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: pg
|