apiotics 0.1.100 → 0.1.101
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/apiotics/server.rb +45 -56
- data/lib/apiotics/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: 58892b459a343aeede24a416eca1b11e663913ca
|
4
|
+
data.tar.gz: eab39b6fdd5d030ce9b8fb84d791ea54f592701d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: daf1d03fcd2f26e3c5f7f83c8b64b9ad1e346bb815147139191afa01f2669cd5095510035f04324e04f927c4982ed38a890b98a4245946bde128157a5e332545
|
7
|
+
data.tar.gz: a679ddece5bc3f8dae4d924098cb1aca6235677ad61c281197b3160a443d047ad6e3b9a6b54cd9d390fc52631ff6ee0500334ce3d5635f44b9fc6924a8676b42
|
data/lib/apiotics/server.rb
CHANGED
@@ -91,77 +91,66 @@ module Apiotics
|
|
91
91
|
end
|
92
92
|
|
93
93
|
def listen_remote
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
end
|
94
|
+
Thread.abort_on_exception = true
|
95
|
+
Thread.new do
|
96
|
+
loop do
|
97
|
+
msg = @server.gets
|
98
|
+
puts msg
|
99
|
+
msg_hash = Apiotics::Parse.message(msg)
|
100
|
+
unless msg_hash["driver"] == "Core::Heartbeat"
|
101
|
+
r = Apiotics::Insert.new(msg_hash)
|
102
|
+
puts "Message received": msg_hash
|
103
|
+
if r.valid == true
|
104
|
+
if r.action == "set-request-ack" || r.action == "set-complete" || r.action == "get-ack"
|
105
|
+
r.save
|
106
|
+
unless Apiotics.configuration.local_logging == false
|
107
|
+
r.save_log
|
109
108
|
end
|
110
109
|
end
|
111
|
-
else
|
112
|
-
monitor_heartbeat(msg_hash)
|
113
110
|
end
|
111
|
+
else
|
112
|
+
monitor_heartbeat(msg_hash)
|
114
113
|
end
|
115
|
-
ActiveRecord::Base.connection.close
|
116
114
|
end
|
117
|
-
|
118
|
-
puts e
|
119
|
-
listen_remote
|
115
|
+
ActiveRecord::Base.connection.close
|
120
116
|
end
|
121
|
-
|
122
117
|
end
|
123
118
|
|
124
119
|
def listen_local
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
if @error_msg != nil
|
150
|
-
string = '{"error":"' + error_msg + '"}'
|
151
|
-
client.puts(string)
|
152
|
-
end
|
153
|
-
#puts msg
|
154
|
-
self.send(msg)
|
155
|
-
end
|
120
|
+
if Apiotics.configuration.redis_comms_connection == false
|
121
|
+
server = TCPServer.open(@localport)
|
122
|
+
loop do
|
123
|
+
Thread.abort_on_exception = true
|
124
|
+
Thread.fork(server.accept) do |client|
|
125
|
+
s = client.gets
|
126
|
+
if @error_msg != nil
|
127
|
+
string = '{"error":"' + error_msg + '"}'
|
128
|
+
client.puts(string)
|
129
|
+
end
|
130
|
+
#puts s
|
131
|
+
self.send(s)
|
132
|
+
end
|
133
|
+
end
|
134
|
+
else
|
135
|
+
redis = ::Redis.new
|
136
|
+
redis.subscribe(Apiotics.configuration.public_key) do |on|
|
137
|
+
on.message do |channel, msg|
|
138
|
+
if @error_msg != nil
|
139
|
+
string = '{"error":"' + error_msg + '"}'
|
140
|
+
client.puts(string)
|
141
|
+
end
|
142
|
+
#puts msg
|
143
|
+
self.send(msg)
|
156
144
|
end
|
157
145
|
end
|
158
|
-
rescue => e
|
159
|
-
puts e
|
160
|
-
listen_local
|
161
146
|
end
|
162
147
|
end
|
163
148
|
|
164
149
|
def send_heartbeat(heartbeat)
|
150
|
+
if Apiotics.configuration.handshake == true
|
151
|
+
self.send('{"action":"connect"}')
|
152
|
+
end
|
153
|
+
Thread.abort_on_exception = true
|
165
154
|
Thread.new do
|
166
155
|
loop do
|
167
156
|
heartbeat["interface"] = DateTime.now.to_i.to_s
|
data/lib/apiotics/version.rb
CHANGED