apiotics 0.1.87 → 0.1.91

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 44afbcbca1eb058e6f36e0b7e691e7b41d98a9f7
4
- data.tar.gz: b13b35e3eb4c4ab62e0941cec47cfbd9021bb7f7
3
+ metadata.gz: b31ad466b84f50973745b403b4ac5ddec4ed902b
4
+ data.tar.gz: b73a87608753aa15394f2e4b0e9cf780628f7163
5
5
  SHA512:
6
- metadata.gz: b0bbac8ed1d49a50edbe592604b59aa59b8f2ca5ee03684de20911e9b1380be64adade05ed6a1a055bcabb79d6207cf29acbe06aa2d5263eea81c2caa84dd0d4
7
- data.tar.gz: 5917625a666b878b8bff88a59bcfa186b20eae8ed95586dea84b35b0bdc2e36e5c8cae97801d256c9eee0bccb711173ea76d16e2c7e7d1c0b224178b3a7fc633
6
+ metadata.gz: 2d87a3c583ef9038958d6b8505f947ee86a7e649f7933ec35be4f245f15dd10829ba3085899eb3845111ed73d35ba6bbcd9eb5cb57f1ec37ae56191957ed5c4d
7
+ data.tar.gz: a39ec503fa05723a6969ea3e85abdcd1c8376e740373094c02080545477e90303e89e6e134b698e115f4ab41b3077e414f739e8b475bf7b074463e0764484670
data/lib/apiotics.rb CHANGED
@@ -7,6 +7,7 @@ require 'apiotics/insert'
7
7
  require 'apiotics/extract'
8
8
  require 'apiotics/portal'
9
9
  require 'apiotics/hardware'
10
+ require 'apiotics/connection_error'
10
11
  require 'daemons'
11
12
 
12
13
  module Apiotics
@@ -1,7 +1,7 @@
1
1
  module Apiotics
2
2
  class Configuration
3
3
 
4
- attr_accessor :public_key, :private_key, :local_logging, :targets, :local_port, :server, :server_port, :portal, :push, :tls, :verify_peer, :handshake, :parents, :reduced_metadata, :redis_comms_connection, :interface_kinds
4
+ attr_accessor :public_key, :private_key, :local_logging, :targets, :local_port, :server, :server_port, :portal, :push, :tls, :verify_peer, :handshake, :parents, :reduced_metadata, :redis_comms_connection, :interface_kinds, :max_missed_heartbeats, :heartbeat_interval
5
5
 
6
6
  def initialize
7
7
  @public_key = nil
@@ -19,6 +19,8 @@ module Apiotics
19
19
  @parents = {}
20
20
  @reduced_metadata = false
21
21
  @redis_comms_connection = false
22
+ @max_missed_heartbeats = 3
23
+ @heartbeat_interval = 5
22
24
  @interface_kinds = {
23
25
  "string" => "string",
24
26
  "text" => "string",
@@ -0,0 +1,9 @@
1
+ module Apiotics
2
+ class ConnectionError < StandardError
3
+
4
+ def initialize(msg="Connection to Hive Server lost.")
5
+ super
6
+ end
7
+
8
+ end
9
+ end
@@ -70,6 +70,15 @@ module Apiotics
70
70
  @localport = Apiotics.configuration.local_port
71
71
  listen_remote
72
72
  listen_local
73
+ @heartbeat_state = Hash.new
74
+ heartbeat = {
75
+ "action" => "set-request",
76
+ "instance" => "0000000000000000000000000000000000000000000000000000000000000000",
77
+ "driver" => "Core::Heartbeat",
78
+ "interface" => nil
79
+ }
80
+ send_heartbeat(heartbeat)
81
+ # need to write a loop that throws an error if the heartbeat is not received back.
73
82
  end
74
83
 
75
84
  def send(msg)
@@ -88,17 +97,22 @@ module Apiotics
88
97
  msg = @server.gets
89
98
  puts msg
90
99
  msg_hash = Apiotics::Parse.message(msg)
91
- r = Apiotics::Insert.new(msg_hash)
92
- puts "Message received": msg_hash
93
- if r.valid == true
94
- if r.action == "set-request-ack" || r.action == "set-complete" || r.action == "get-ack"
95
- r.save
96
- unless Apiotics.configuration.local_logging == false
97
- r.save_log
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
108
+ end
98
109
  end
99
110
  end
111
+ else
112
+ monitor_heartbeat(msg_hash)
100
113
  end
101
114
  end
115
+ ActiveRecord::Base.connection.close
102
116
  end
103
117
  rescue => e
104
118
  puts e
@@ -147,6 +161,26 @@ module Apiotics
147
161
  end
148
162
  end
149
163
 
164
+ def send_heartbeat(heartbeat)
165
+ loop do
166
+ heartbeat["interface"] = DateTime.now.to_i
167
+ self.send(heartbeat)
168
+ self.monitor_heartbeat(heartbeat)
169
+ sleep Apiotics.configuration.heartbeat_interval
170
+ end
171
+ end
172
+
173
+ def monitor_heartbeat(heartbeat)
174
+ if heartbeat["action"] = "set-request"
175
+ @heartbeat_state[heartbeat["interface"]] = heartbeat
176
+ elsif heartbeat["action"] = "set-request-ack"
177
+ @heartbeat_state.delete(heartbeat["interface"])
178
+ end
179
+ if @heartbeat_state.length > Apiotics.configuration.max_missed_heartbeats
180
+ raise Apiotics::ConnectionError
181
+ end
182
+ end
183
+
150
184
  def self.lookup
151
185
  if Apiotics.configuration.tls == true
152
186
  socket = TCPSocket.new(Apiotics.configuration.server, Apiotics.configuration.server_port)
@@ -1,3 +1,3 @@
1
1
  module Apiotics
2
- VERSION = '0.1.87'
2
+ VERSION = '0.1.91'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: apiotics
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.87
4
+ version: 0.1.91
5
5
  platform: ruby
6
6
  authors:
7
7
  - MicroArx Corporation
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-12-15 00:00:00.000000000 Z
11
+ date: 2017-12-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -162,6 +162,7 @@ files:
162
162
  - lib/apiotics.rb
163
163
  - lib/apiotics/client.rb
164
164
  - lib/apiotics/configuration.rb
165
+ - lib/apiotics/connection_error.rb
165
166
  - lib/apiotics/extract.rb
166
167
  - lib/apiotics/hardware.rb
167
168
  - lib/apiotics/insert.rb