airship-ruby 1.1.1 → 1.1.2
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 +4 -4
- data/airship-ruby.gemspec +1 -1
- data/lib/airship-ruby.rb +184 -171
- 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: ac94177d71469e596c7ffb61a4c5c1eee838f196
|
4
|
+
data.tar.gz: 7d10788fa32c0e7cb90b797ef11dd77a3efd8a93
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8b53ba8664daa2506ce385cf94465a18366bdfc3cb0cab132a457708ed81e46756878f358910765db60d08cdbb0d70163d39fd4167379eb5f4e06348860a9b23
|
7
|
+
data.tar.gz: 0c759743a09c30112e1f01ea942d222330641cd5b6993fdf81725f0d8e9763a7ac0705d18eeeb7630324a4d732a383c20d66bf499d43e2fbb8af7375d582503a
|
data/airship-ruby.gemspec
CHANGED
data/lib/airship-ruby.rb
CHANGED
@@ -169,6 +169,7 @@ class Airship
|
|
169
169
|
|
170
170
|
@gating_info = nil
|
171
171
|
@gating_info_downloader_task = nil
|
172
|
+
@gating_info_polling_interval = 60
|
172
173
|
|
173
174
|
@gating_info_map = nil
|
174
175
|
|
@@ -182,12 +183,18 @@ class Airship
|
|
182
183
|
|
183
184
|
@gate_stats_batch = []
|
184
185
|
|
186
|
+
@initialization_lock = Concurrent::Semaphore.new(1)
|
185
187
|
@gate_stats_batch_lock = Concurrent::Semaphore.new(1)
|
186
188
|
end
|
187
189
|
|
188
190
|
def init
|
189
|
-
|
191
|
+
@initialization_lock.acquire
|
190
192
|
if @gating_info_downloader_task.nil?
|
193
|
+
self._poll
|
194
|
+
if @gating_info.nil?
|
195
|
+
@initialization_lock.release
|
196
|
+
raise Exception.new('Failed to connect to Airship server')
|
197
|
+
end
|
191
198
|
@gating_info_downloader_task = self._create_poller
|
192
199
|
@gating_info_downloader_task.execute
|
193
200
|
end
|
@@ -196,9 +203,167 @@ class Airship
|
|
196
203
|
@gate_stats_watcher = self._create_watcher
|
197
204
|
@gate_stats_watcher.execute
|
198
205
|
end
|
199
|
-
|
206
|
+
@initialization_lock.release
|
207
|
+
end
|
208
|
+
|
209
|
+
def enabled?(control_short_name, object, default_value=false)
|
210
|
+
validation_errors = JSON::Validator.fully_validate(SCHEMA, object)
|
211
|
+
if validation_errors.size > 0
|
212
|
+
puts validation_errors[0]
|
213
|
+
return default_value
|
214
|
+
end
|
215
|
+
|
216
|
+
object = self._clone_object(object)
|
217
|
+
|
218
|
+
error = self._validate_nesting(object)
|
219
|
+
|
220
|
+
if !error.nil?
|
221
|
+
puts error
|
222
|
+
return default_value
|
223
|
+
end
|
224
|
+
|
225
|
+
if @gating_info_map.nil?
|
226
|
+
return default_value
|
227
|
+
end
|
228
|
+
|
229
|
+
gate_timestamp = Time.now.iso8601
|
230
|
+
|
231
|
+
start = Time.now
|
232
|
+
|
233
|
+
gate_values = self._get_gate_values(control_short_name, object)
|
234
|
+
is_enabled = gate_values['is_enabled']
|
235
|
+
variation = gate_values['variation']
|
236
|
+
is_eligible = gate_values['is_eligible']
|
237
|
+
_should_send_stats = gate_values['_should_send_stats']
|
238
|
+
|
239
|
+
finish = Time.now
|
240
|
+
|
241
|
+
if _should_send_stats
|
242
|
+
sdk_gate_timestamp = gate_timestamp
|
243
|
+
sdk_gate_latency = "#{(finish - start) * 1000 * 1000}us"
|
244
|
+
sdk_version = SDK_VERSION
|
245
|
+
|
246
|
+
stats = {}
|
247
|
+
stats['sdk_gate_control_short_name'] = control_short_name
|
248
|
+
stats['sdk_gate_timestamp'] = sdk_gate_timestamp
|
249
|
+
stats['sdk_gate_latency'] = sdk_gate_latency
|
250
|
+
stats['sdk_version'] = sdk_version
|
251
|
+
stats['sdk_id'] = @@sdk_id
|
252
|
+
|
253
|
+
object['stats'] = stats
|
254
|
+
|
255
|
+
self._upload_stats_async(object)
|
256
|
+
end
|
257
|
+
|
258
|
+
return is_enabled
|
259
|
+
end
|
260
|
+
|
261
|
+
def variation(control_short_name, object, default_value=nil)
|
262
|
+
validation_errors = JSON::Validator.fully_validate(SCHEMA, object)
|
263
|
+
if validation_errors.size > 0
|
264
|
+
puts validation_errors[0]
|
265
|
+
return default_value
|
266
|
+
end
|
267
|
+
|
268
|
+
object = self._clone_object(object)
|
269
|
+
|
270
|
+
error = self._validate_nesting(object)
|
271
|
+
|
272
|
+
if !error.nil?
|
273
|
+
puts error
|
274
|
+
return default_value
|
275
|
+
end
|
276
|
+
|
277
|
+
if @gating_info_map.nil?
|
278
|
+
return default_value
|
279
|
+
end
|
280
|
+
|
281
|
+
gate_timestamp = Time.now.iso8601
|
282
|
+
|
283
|
+
start = Time.now
|
284
|
+
|
285
|
+
gate_values = self._get_gate_values(control_short_name, object)
|
286
|
+
is_enabled = gate_values['is_enabled']
|
287
|
+
variation = gate_values['variation']
|
288
|
+
is_eligible = gate_values['is_eligible']
|
289
|
+
_should_send_stats = gate_values['_should_send_stats']
|
290
|
+
|
291
|
+
finish = Time.now
|
292
|
+
|
293
|
+
if _should_send_stats
|
294
|
+
sdk_gate_timestamp = gate_timestamp
|
295
|
+
sdk_gate_latency = "#{(finish - start) * 1000 * 1000}us"
|
296
|
+
sdk_version = SDK_VERSION
|
297
|
+
|
298
|
+
stats = {}
|
299
|
+
stats['sdk_gate_control_short_name'] = control_short_name
|
300
|
+
stats['sdk_gate_timestamp'] = sdk_gate_timestamp
|
301
|
+
stats['sdk_gate_latency'] = sdk_gate_latency
|
302
|
+
stats['sdk_version'] = sdk_version
|
303
|
+
stats['sdk_id'] = @@sdk_id
|
304
|
+
|
305
|
+
object['stats'] = stats
|
306
|
+
|
307
|
+
self._upload_stats_async(object)
|
308
|
+
end
|
309
|
+
|
310
|
+
return variation
|
311
|
+
end
|
312
|
+
|
313
|
+
def eligible?(control_short_name, object, default_value=false)
|
314
|
+
validation_errors = JSON::Validator.fully_validate(SCHEMA, object)
|
315
|
+
if validation_errors.size > 0
|
316
|
+
puts validation_errors[0]
|
317
|
+
return default_value
|
318
|
+
end
|
319
|
+
|
320
|
+
object = self._clone_object(object)
|
321
|
+
|
322
|
+
error = self._validate_nesting(object)
|
323
|
+
|
324
|
+
if !error.nil?
|
325
|
+
puts error
|
326
|
+
return default_value
|
327
|
+
end
|
328
|
+
|
329
|
+
if @gating_info_map.nil?
|
330
|
+
return default_value
|
331
|
+
end
|
332
|
+
|
333
|
+
gate_timestamp = Time.now.iso8601
|
334
|
+
|
335
|
+
start = Time.now
|
336
|
+
|
337
|
+
gate_values = self._get_gate_values(control_short_name, object)
|
338
|
+
is_enabled = gate_values['is_enabled']
|
339
|
+
variation = gate_values['variation']
|
340
|
+
is_eligible = gate_values['is_eligible']
|
341
|
+
_should_send_stats = gate_values['_should_send_stats']
|
342
|
+
|
343
|
+
finish = Time.now
|
344
|
+
|
345
|
+
if _should_send_stats
|
346
|
+
sdk_gate_timestamp = gate_timestamp
|
347
|
+
sdk_gate_latency = "#{(finish - start) * 1000 * 1000}us"
|
348
|
+
sdk_version = SDK_VERSION
|
349
|
+
|
350
|
+
stats = {}
|
351
|
+
stats['sdk_gate_control_short_name'] = control_short_name
|
352
|
+
stats['sdk_gate_timestamp'] = sdk_gate_timestamp
|
353
|
+
stats['sdk_gate_latency'] = sdk_gate_latency
|
354
|
+
stats['sdk_version'] = sdk_version
|
355
|
+
stats['sdk_id'] = @@sdk_id
|
356
|
+
|
357
|
+
object['stats'] = stats
|
358
|
+
|
359
|
+
self._upload_stats_async(object)
|
360
|
+
end
|
361
|
+
|
362
|
+
return is_eligible
|
200
363
|
end
|
201
364
|
|
365
|
+
protected
|
366
|
+
|
202
367
|
def _get_gating_info_map(gating_info)
|
203
368
|
map = {}
|
204
369
|
|
@@ -236,24 +401,28 @@ class Airship
|
|
236
401
|
map
|
237
402
|
end
|
238
403
|
|
404
|
+
def _poll
|
405
|
+
conn = Faraday.new(url: "#{GATING_INFO_ENDPOINT}/#{@env_key}")
|
406
|
+
response = conn.get do |req|
|
407
|
+
req.options.timeout = 10
|
408
|
+
req.headers['api-key'] = @api_key
|
409
|
+
end
|
410
|
+
if response.status == 200
|
411
|
+
gating_info = JSON.parse(response.body)
|
412
|
+
gating_info_map = self._get_gating_info_map(gating_info)
|
413
|
+
@gating_info = gating_info
|
414
|
+
@gating_info_map = gating_info_map
|
415
|
+
end
|
416
|
+
end
|
417
|
+
|
239
418
|
def _create_poller
|
240
|
-
Concurrent::TimerTask.new(execution_interval:
|
241
|
-
|
242
|
-
response = conn.get do |req|
|
243
|
-
req.options.timeout = 10
|
244
|
-
req.headers['api-key'] = @api_key
|
245
|
-
end
|
246
|
-
if response.status == 200
|
247
|
-
gating_info = JSON.parse(response.body)
|
248
|
-
gating_info_map = self._get_gating_info_map(gating_info)
|
249
|
-
@gating_info = gating_info
|
250
|
-
@gating_info_map = gating_info_map
|
251
|
-
end
|
419
|
+
Concurrent::TimerTask.new(execution_interval: @gating_info_polling_interval, timeout_interval: 10) do |task|
|
420
|
+
self._poll
|
252
421
|
end
|
253
422
|
end
|
254
423
|
|
255
424
|
def _create_watcher
|
256
|
-
Concurrent::TimerTask.new(execution_interval: @gate_stats_upload_batch_interval, timeout_interval: 10
|
425
|
+
Concurrent::TimerTask.new(execution_interval: @gate_stats_upload_batch_interval, timeout_interval: 10) do |task|
|
257
426
|
now = Time.now.utc.to_i
|
258
427
|
if now - @gate_stats_last_task_scheduled_timestamp.value >= @gate_stats_upload_batch_interval
|
259
428
|
processed = self._process_batch(0)
|
@@ -714,160 +883,4 @@ class Airship
|
|
714
883
|
return 'A group cannot be nested inside another group'
|
715
884
|
end
|
716
885
|
end
|
717
|
-
|
718
|
-
def enabled?(control_short_name, object)
|
719
|
-
if @gating_info_map.nil?
|
720
|
-
return false
|
721
|
-
end
|
722
|
-
|
723
|
-
validation_errors = JSON::Validator.fully_validate(SCHEMA, object)
|
724
|
-
if validation_errors.size > 0
|
725
|
-
puts validation_errors[0]
|
726
|
-
return false
|
727
|
-
end
|
728
|
-
|
729
|
-
object = self._clone_object(object)
|
730
|
-
|
731
|
-
error = self._validate_nesting(object)
|
732
|
-
|
733
|
-
if !error.nil?
|
734
|
-
puts error
|
735
|
-
return false
|
736
|
-
end
|
737
|
-
|
738
|
-
gate_timestamp = Time.now.iso8601
|
739
|
-
|
740
|
-
start = Time.now
|
741
|
-
|
742
|
-
gate_values = self._get_gate_values(control_short_name, object)
|
743
|
-
is_enabled = gate_values['is_enabled']
|
744
|
-
variation = gate_values['variation']
|
745
|
-
is_eligible = gate_values['is_eligible']
|
746
|
-
_should_send_stats = gate_values['_should_send_stats']
|
747
|
-
|
748
|
-
finish = Time.now
|
749
|
-
|
750
|
-
if _should_send_stats
|
751
|
-
sdk_gate_timestamp = gate_timestamp
|
752
|
-
sdk_gate_latency = "#{(finish - start) * 1000 * 1000}us"
|
753
|
-
sdk_version = SDK_VERSION
|
754
|
-
|
755
|
-
stats = {}
|
756
|
-
stats['sdk_gate_control_short_name'] = control_short_name
|
757
|
-
stats['sdk_gate_timestamp'] = sdk_gate_timestamp
|
758
|
-
stats['sdk_gate_latency'] = sdk_gate_latency
|
759
|
-
stats['sdk_version'] = sdk_version
|
760
|
-
stats['sdk_id'] = @@sdk_id
|
761
|
-
|
762
|
-
object['stats'] = stats
|
763
|
-
|
764
|
-
self._upload_stats_async(object)
|
765
|
-
end
|
766
|
-
|
767
|
-
return is_enabled
|
768
|
-
end
|
769
|
-
|
770
|
-
def variation(control_short_name, object)
|
771
|
-
if @gating_info_map.nil?
|
772
|
-
return nil
|
773
|
-
end
|
774
|
-
|
775
|
-
validation_errors = JSON::Validator.fully_validate(SCHEMA, object)
|
776
|
-
if validation_errors.size > 0
|
777
|
-
puts validation_errors[0]
|
778
|
-
return nil
|
779
|
-
end
|
780
|
-
|
781
|
-
object = self._clone_object(object)
|
782
|
-
|
783
|
-
error = self._validate_nesting(object)
|
784
|
-
|
785
|
-
if !error.nil?
|
786
|
-
puts error
|
787
|
-
return nil
|
788
|
-
end
|
789
|
-
|
790
|
-
gate_timestamp = Time.now.iso8601
|
791
|
-
|
792
|
-
start = Time.now
|
793
|
-
|
794
|
-
gate_values = self._get_gate_values(control_short_name, object)
|
795
|
-
is_enabled = gate_values['is_enabled']
|
796
|
-
variation = gate_values['variation']
|
797
|
-
is_eligible = gate_values['is_eligible']
|
798
|
-
_should_send_stats = gate_values['_should_send_stats']
|
799
|
-
|
800
|
-
finish = Time.now
|
801
|
-
|
802
|
-
if _should_send_stats
|
803
|
-
sdk_gate_timestamp = gate_timestamp
|
804
|
-
sdk_gate_latency = "#{(finish - start) * 1000 * 1000}us"
|
805
|
-
sdk_version = SDK_VERSION
|
806
|
-
|
807
|
-
stats = {}
|
808
|
-
stats['sdk_gate_control_short_name'] = control_short_name
|
809
|
-
stats['sdk_gate_timestamp'] = sdk_gate_timestamp
|
810
|
-
stats['sdk_gate_latency'] = sdk_gate_latency
|
811
|
-
stats['sdk_version'] = sdk_version
|
812
|
-
stats['sdk_id'] = @@sdk_id
|
813
|
-
|
814
|
-
object['stats'] = stats
|
815
|
-
|
816
|
-
self._upload_stats_async(object)
|
817
|
-
end
|
818
|
-
|
819
|
-
return variation
|
820
|
-
end
|
821
|
-
|
822
|
-
def eligible?(control_short_name, object)
|
823
|
-
if @gating_info_map.nil?
|
824
|
-
return false
|
825
|
-
end
|
826
|
-
|
827
|
-
validation_errors = JSON::Validator.fully_validate(SCHEMA, object)
|
828
|
-
if validation_errors.size > 0
|
829
|
-
puts validation_errors[0]
|
830
|
-
return false
|
831
|
-
end
|
832
|
-
|
833
|
-
object = self._clone_object(object)
|
834
|
-
|
835
|
-
error = self._validate_nesting(object)
|
836
|
-
|
837
|
-
if !error.nil?
|
838
|
-
puts error
|
839
|
-
return false
|
840
|
-
end
|
841
|
-
|
842
|
-
gate_timestamp = Time.now.iso8601
|
843
|
-
|
844
|
-
start = Time.now
|
845
|
-
|
846
|
-
gate_values = self._get_gate_values(control_short_name, object)
|
847
|
-
is_enabled = gate_values['is_enabled']
|
848
|
-
variation = gate_values['variation']
|
849
|
-
is_eligible = gate_values['is_eligible']
|
850
|
-
_should_send_stats = gate_values['_should_send_stats']
|
851
|
-
|
852
|
-
finish = Time.now
|
853
|
-
|
854
|
-
if _should_send_stats
|
855
|
-
sdk_gate_timestamp = gate_timestamp
|
856
|
-
sdk_gate_latency = "#{(finish - start) * 1000 * 1000}us"
|
857
|
-
sdk_version = SDK_VERSION
|
858
|
-
|
859
|
-
stats = {}
|
860
|
-
stats['sdk_gate_control_short_name'] = control_short_name
|
861
|
-
stats['sdk_gate_timestamp'] = sdk_gate_timestamp
|
862
|
-
stats['sdk_gate_latency'] = sdk_gate_latency
|
863
|
-
stats['sdk_version'] = sdk_version
|
864
|
-
stats['sdk_id'] = @@sdk_id
|
865
|
-
|
866
|
-
object['stats'] = stats
|
867
|
-
|
868
|
-
self._upload_stats_async(object)
|
869
|
-
end
|
870
|
-
|
871
|
-
return is_eligible
|
872
|
-
end
|
873
886
|
end
|