apiotics 0.1.138 → 0.1.139

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 926cd922c98a9768fa045d4ddc33872171581786
4
- data.tar.gz: 3637e7d3c43c0df5fa4c2507f838639215f0e66b
3
+ metadata.gz: 22055fe4401e0b436332e2cd3d52ae87e4cef3c0
4
+ data.tar.gz: 95d717c41a50f1d9f6e176495d29eaad844d54f5
5
5
  SHA512:
6
- metadata.gz: 48aad72c6a815f6d3c9104e609be79c15304e21305311a28c4a127dc657cb068be92a57a43e8b599e6a4b6722871cc1092410763b161f193b849c1b7719eab44
7
- data.tar.gz: 0c6f3cf89156258a04bf30add4a5eea2490fbc5f64d878bc0b1aa348caf8297f10fea76659fdf488eb986adc6e8094c4e22d4548bc96e5533eae883e4ddc2ff3
6
+ metadata.gz: d4e76ca5970cbfb3be6746231165c11a6d29627996386751d0d53cdf358a8949a046d57609cd47047483c574ea3ff8f0d87776057e00e6cd76f92acb15879448
7
+ data.tar.gz: 9f403ce33aff3867699e5ddea4a8f67441fed980b600ed25fc94af71ee120a4d9f1fa3edaf441dc04bc09e2fe219348a85acd659fa364e704321d76ebab8b45c
@@ -73,6 +73,7 @@ module Apiotics
73
73
  else
74
74
  @server = TCPSocket.open(rgs, rgs_port)
75
75
  end
76
+ Server.sync_devices(nil)
76
77
  @localport = Apiotics.configuration.local_port
77
78
  listen_remote
78
79
  @heartbeat_state = Hash.new
@@ -113,7 +114,7 @@ module Apiotics
113
114
  puts "Message received: " + msg
114
115
  msg_hash = Apiotics::Parse.message(msg)
115
116
  #puts "Driver: " + msg_hash["driver"]
116
- unless msg_hash["driver"] == "Core::Heartbeat" || msg_hash["error"] != nil
117
+ unless msg_hash["driver"] == "Core::Heartbeat" || msg_hash["action"] == "sync" || msg_hash["error"] != nil
117
118
  r = Apiotics::Insert.new(msg_hash)
118
119
  if r.valid == true
119
120
  if r.action == "set-request-ack" || r.action == "set-complete" || r.action == "get-ack"
@@ -123,8 +124,24 @@ module Apiotics
123
124
  end
124
125
  end
125
126
  end
126
- else
127
+ end
128
+ if msg_hash["driver"] == "Core::Heartbeat"
127
129
  monitor_heartbeat(msg_hash)
130
+ elsif msg_hash["action"] == "sync"
131
+ if Server.sync_devices(msg_hash["worker"])
132
+ sync_msg = {
133
+ "action" => "sync-ack",
134
+ "worker" => msg_hash["worker"],
135
+ "status" => "ok"
136
+ }
137
+ else
138
+ sync_msg = {
139
+ "action" => "sync-ack",
140
+ "worker" => msg_hash["worker"],
141
+ "status" => "error"
142
+ }
143
+ end
144
+ self.send(sync_msg.to_json)
128
145
  end
129
146
  end
130
147
  rescue => e
@@ -214,6 +231,30 @@ module Apiotics
214
231
  end
215
232
  end
216
233
 
234
+ def self.sync_devices(model_name)
235
+ value = false
236
+ if model_name == nil
237
+ unless Rails.env.production?
238
+ Rails.application.eager_load!
239
+ end
240
+ models = ApplicationRecord.descendants.collect(&:name)
241
+ else
242
+ model_name = model_name + "::" + model_name
243
+ models = [model_name]
244
+ end
245
+ workers = []
246
+ models.each do |m|
247
+ if Apiotics.configuration.targets.keys.include?(m.deconstantize)
248
+ workers << m.deconstantize
249
+ end
250
+ end
251
+ workers.each do |w|
252
+ w.deconstantize.sync_devices
253
+ value = true
254
+ end
255
+ return value
256
+ end
257
+
217
258
  def self.lookup
218
259
  if Apiotics.configuration.tls == true
219
260
  socket = TCPSocket.new(Apiotics.configuration.server, Apiotics.configuration.server_port)
@@ -1,3 +1,3 @@
1
1
  module Apiotics
2
- VERSION = '0.1.138'
2
+ VERSION = '0.1.139'
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.138
4
+ version: 0.1.139
5
5
  platform: ruby
6
6
  authors:
7
7
  - MicroArx Corporation
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-04-10 00:00:00.000000000 Z
11
+ date: 2018-04-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails