airship-ruby 1.1.9 → 1.1.10

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
  SHA256:
3
- metadata.gz: bc2837e7860439e13430504df151ad1c65ff14f773d6a5cd8b9769bb72f7d878
4
- data.tar.gz: 1829c67d1db585fee1b42270333a45a89cc2d4cb1d6c89cc8f9d661247266e3a
3
+ metadata.gz: 3d59b238a7a3c148f227bf5cee84afdea2b05d503cc4c09cb32099cedb2f124a
4
+ data.tar.gz: 8995be1f77fa3c2b4bb28ab3e0b59c398e4b93aa42c2e06105c5c6e5c49b40ad
5
5
  SHA512:
6
- metadata.gz: 26681353e4fabc3e58323cc15f7b6746b049d15287aeca26c614edce6b966f7a7c80f464f8fff713fc840054ab22a0fda61e93875f29850b8d0e0509a74c272f
7
- data.tar.gz: 1dc98c73102a028a5a07a406a00909adaf613b411953f3c7d332aa4fc52d3bc6619043910ba42949cac557790d0d51b1ae8dc77f60482cca4e2694c4d8e0daec
6
+ metadata.gz: 1aa178627ab85311d5526a4fe04c73af313f12fb3c77792caa20d7b59d76898bf846426e2ac125e7abf132c2c879a2d1eba3ff6c9fd7cb60ff6bf4de7df9aace
7
+ data.tar.gz: 1c6f2fa64fb2833b3a6cea08ece255cc02bbe5e88c66fb62a6a07298c18c8074a32a3513e4436350481f3f10570f3e9e11827af736a48185a7c14a49bb20559e
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = "airship-ruby"
3
- s.version = "1.1.9"
3
+ s.version = "1.1.10"
4
4
  s.licenses = ["MIT"]
5
5
  s.summary = "Airship Ruby SDK"
6
6
  s.description = "Ruby SDK"
@@ -9,8 +9,8 @@ Gem::Specification.new do |s|
9
9
  s.files = ["lib/airship-ruby.rb", "airship-ruby.gemspec"]
10
10
  s.homepage = "https://airshiphq.com"
11
11
  s.metadata = { "source_code_uri" => "https://github.com/airshiphq/airship-ruby" }
12
- s.add_runtime_dependency "faraday", ">= 0.9.0"
13
- s.add_runtime_dependency "json", ">= 1.8.2"
14
- s.add_runtime_dependency "concurrent-ruby", ">= 1.0.3"
15
- s.add_runtime_dependency "json-schema", ">= 2.5.0"
12
+ s.add_runtime_dependency "faraday", "~> 0.9", ">= 0.9.0"
13
+ s.add_runtime_dependency "json", "~> 1.8", ">= 1.8.2"
14
+ s.add_runtime_dependency "concurrent-ruby", "~> 1.0", ">= 1.0.3"
15
+ s.add_runtime_dependency "json-schema", "~> 2.5", ">= 2.5.0"
16
16
  end
@@ -160,56 +160,44 @@ class Airship
160
160
  end
161
161
 
162
162
  def initialize(options)
163
-
164
163
  @api_key = options[:api_key]
165
164
  @env_key = options[:env_key]
165
+ @timeout = 10
166
166
 
167
- if @api_key.nil?
168
- raise Exception.new('Missing api_key')
169
- end
167
+ @polling_interval = 60
168
+ @ingestion_interval = 60
170
169
 
171
- if @env_key.nil?
172
- raise Exception.new('Missing env_key')
173
- end
170
+ @polling_thread = nil
171
+ @ingestion_thread = nil
174
172
 
175
173
  @gating_info = nil
176
- @gating_info_downloader_task = nil
177
- @gating_info_polling_interval = 60
178
-
179
174
  @gating_info_map = nil
180
175
 
181
- @max_gate_stats_batch_size = 500
182
- @gate_stats_upload_batch_interval = 60
176
+ @last_ingestion_timestamp = 0
177
+ @ingestion_tasks = []
183
178
 
184
- @gate_stats_watcher = nil
185
- @gate_stats_last_task_scheduled_timestamp = 0
179
+ @ingestion_batch = []
180
+ @ingestion_max_batch_size = 500
186
181
 
187
- @gate_stats_uploader_tasks = []
182
+ @init_lock = Concurrent::Semaphore.new(1)
183
+ @ingestion_batch_lock = Concurrent::Semaphore.new(1)
188
184
 
189
- @gate_stats_batch = []
190
-
191
- @initialization_lock = Concurrent::Semaphore.new(1)
192
- @gate_stats_batch_lock = Concurrent::Semaphore.new(1)
193
-
194
- @first_gate = true
185
+ @first_ingestion = true
195
186
  end
196
187
 
197
188
  def init
198
- @initialization_lock.acquire
199
- if @gating_info_downloader_task.nil?
189
+ @init_lock.acquire
190
+ if @polling_thread.nil?
200
191
  self._poll
201
- if @gating_info.nil?
202
- puts 'Failed to connect to Airship server'
203
- end
204
- @gating_info_downloader_task = self._create_poller
205
- @gating_info_downloader_task.execute
192
+ @polling_thread = self._create_poller
193
+ @polling_thread.execute
206
194
  end
207
195
 
208
- if @gate_stats_watcher.nil?
209
- @gate_stats_watcher = self._create_watcher
210
- @gate_stats_watcher.execute
196
+ if @ingestion_thread.nil?
197
+ @ingestion_thread = self._create_ingestor
198
+ @ingestion_thread.execute
211
199
  end
212
- @initialization_lock.release
200
+ @init_lock.release
213
201
  self
214
202
  end
215
203
 
@@ -271,7 +259,7 @@ class Airship
271
259
 
272
260
  object['stats'] = stats
273
261
 
274
- self._upload_stats_async(object)
262
+ self._ingest_async(object)
275
263
  end
276
264
 
277
265
  return is_enabled
@@ -335,7 +323,7 @@ class Airship
335
323
 
336
324
  object['stats'] = stats
337
325
 
338
- self._upload_stats_async(object)
326
+ self._ingest_async(object)
339
327
  end
340
328
 
341
329
  return variation
@@ -399,7 +387,7 @@ class Airship
399
387
 
400
388
  object['stats'] = stats
401
389
 
402
- self._upload_stats_async(object)
390
+ self._ingest_async(object)
403
391
  end
404
392
 
405
393
  return is_eligible
@@ -460,53 +448,66 @@ class Airship
460
448
  begin
461
449
  conn = Faraday.new(url: "#{GATING_INFO_ENDPOINT}/#{@env_key}")
462
450
  response = conn.get do |req|
463
- req.options.timeout = 10
451
+ req.options.timeout = @timeout
464
452
  req.headers['api-key'] = @api_key
465
453
  end
466
454
  if response.status == 200
467
455
  gating_info = JSON.parse(response.body)
468
456
 
469
457
  if gating_info['server_info'] == 'maintenance'
458
+ puts 'Airship is currently going through maintenance'
470
459
  return
471
460
  end
472
461
 
473
462
  gating_info_map = self._get_gating_info_map(gating_info)
474
463
  @gating_info = gating_info
475
464
  @gating_info_map = gating_info_map
465
+
466
+ if !gating_info['polling_interval'].nil?
467
+ self.polling_interval = gating_info['polling_interval']
468
+ end
469
+
470
+ if !gating_info['ingestion_interval'].nil?
471
+ self.ingestion_interval = gating_info['ingestion_interval']
472
+ end
473
+ else
474
+ puts 'Failed to connect to Airship server'
476
475
  end
477
476
  rescue Exception => e
478
- puts 'Failed to poll'
477
+ puts 'Failed to connect to Airship server'
479
478
  end
480
479
  end
481
480
 
482
481
  def _create_poller
483
- Concurrent::TimerTask.new(execution_interval: @gating_info_polling_interval, timeout_interval: 10) do |task|
482
+ Concurrent::TimerTask.new(execution_interval: @polling_interval, timeout_interval: @timeout) do |task|
484
483
  self._poll
484
+ task.execution_interval = @polling_interval
485
485
  end
486
486
  end
487
487
 
488
- def _create_watcher
489
- Concurrent::TimerTask.new(execution_interval: @gate_stats_upload_batch_interval, timeout_interval: 10) do |task|
488
+ def _create_ingestor
489
+ Concurrent::TimerTask.new(execution_interval: @ingestion_interval, timeout_interval: @timeout) do |task|
490
490
  now = Time.now.utc.to_i
491
- if now - @gate_stats_last_task_scheduled_timestamp >= @gate_stats_upload_batch_interval
491
+ if now - @last_ingestion_timestamp >= @ingestion_interval
492
492
  processed = self._process_batch(0)
493
493
  if processed
494
- @gate_stats_last_task_scheduled_timestamp = now
494
+ @last_ingestion_timestamp = now
495
495
  end
496
496
  end
497
+ task.execution_interval = @ingestion_interval
497
498
  end
498
499
  end
499
500
 
500
- def _create_processor(batch)
501
+ def _create_processor(payload)
501
502
  return Concurrent::ScheduledTask.execute(0) do |task|
502
503
  conn = Faraday.new(url: IDENTIFY_ENDPOINT)
503
504
  response = conn.post do |req|
504
- req.options.timeout = 10
505
+ req.options.timeout = @timeout
505
506
  req.headers['Content-Type'] = 'application/json'
506
507
  req.headers['api-key'] = @api_key
507
508
  req.body = JSON.generate({
508
509
  'env_key' => @env_key,
509
- 'objects' => batch,
510
+ 'objects' => payload,
510
511
  })
511
512
  end
512
513
  end
@@ -521,33 +522,33 @@ class Airship
521
522
  # is performed.
522
523
 
523
524
  processed = false
524
- @gate_stats_batch_lock.acquire
525
+ @ingestion_batch_lock.acquire
525
526
  if !gate_stats.nil?
526
- @gate_stats_batch.push(gate_stats)
527
+ @ingestion_batch.push(gate_stats)
527
528
  end
528
- if @gate_stats_batch.size > limit || (@first_gate && @gate_stats_batch.size > 0)
529
- @first_gate = false
530
- new_gate_stats_uploader_tasks = []
531
- @gate_stats_uploader_tasks.each do |task|
529
+ if @ingestion_batch.size > limit || (@first_ingestion && @ingestion_batch.size > 0)
530
+ @first_ingestion = false
531
+ new_ingestion_tasks = []
532
+ @ingestion_tasks.each do |task|
532
533
  if !task.fulfilled?
533
- new_gate_stats_uploader_tasks.push(task)
534
+ new_ingestion_tasks.push(task)
534
535
  end
535
536
  end
536
- old_batch = @gate_stats_batch
537
- @gate_stats_batch = []
538
- new_gate_stats_uploader_tasks.push(self._create_processor(old_batch))
539
- @gate_stats_uploader_tasks = new_gate_stats_uploader_tasks
537
+ payload = @ingestion_batch
538
+ @ingestion_batch = []
539
+ new_ingestion_tasks.push(self._create_processor(payload))
540
+ @ingestion_tasks = new_ingestion_tasks
540
541
  processed = true
541
542
  end
542
- @gate_stats_batch_lock.release
543
+ @ingestion_batch_lock.release
543
544
  processed
544
545
  end
545
546
 
546
- def _upload_stats_async(gate_stats)
547
- processed = self._process_batch(@max_gate_stats_batch_size - 1, gate_stats)
547
+ def _ingest_async(gate_stats)
548
+ processed = self._process_batch(@ingestion_max_batch_size - 1, gate_stats)
548
549
  if processed
549
550
  now = Time.now.utc.to_i
550
- @gate_stats_last_task_scheduled_timestamp = now
551
+ @last_ingestion_timestamp = now
551
552
  end
552
553
  end
553
554
 
metadata CHANGED
@@ -1,19 +1,22 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: airship-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.9
4
+ version: 1.1.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - Airship Dev Team
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-04-12 00:00:00.000000000 Z
11
+ date: 2018-05-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '0.9'
17
20
  - - ">="
18
21
  - !ruby/object:Gem::Version
19
22
  version: 0.9.0
@@ -21,6 +24,9 @@ dependencies:
21
24
  prerelease: false
22
25
  version_requirements: !ruby/object:Gem::Requirement
23
26
  requirements:
27
+ - - "~>"
28
+ - !ruby/object:Gem::Version
29
+ version: '0.9'
24
30
  - - ">="
25
31
  - !ruby/object:Gem::Version
26
32
  version: 0.9.0
@@ -28,6 +34,9 @@ dependencies:
28
34
  name: json
29
35
  requirement: !ruby/object:Gem::Requirement
30
36
  requirements:
37
+ - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: '1.8'
31
40
  - - ">="
32
41
  - !ruby/object:Gem::Version
33
42
  version: 1.8.2
@@ -35,6 +44,9 @@ dependencies:
35
44
  prerelease: false
36
45
  version_requirements: !ruby/object:Gem::Requirement
37
46
  requirements:
47
+ - - "~>"
48
+ - !ruby/object:Gem::Version
49
+ version: '1.8'
38
50
  - - ">="
39
51
  - !ruby/object:Gem::Version
40
52
  version: 1.8.2
@@ -42,6 +54,9 @@ dependencies:
42
54
  name: concurrent-ruby
43
55
  requirement: !ruby/object:Gem::Requirement
44
56
  requirements:
57
+ - - "~>"
58
+ - !ruby/object:Gem::Version
59
+ version: '1.0'
45
60
  - - ">="
46
61
  - !ruby/object:Gem::Version
47
62
  version: 1.0.3
@@ -49,6 +64,9 @@ dependencies:
49
64
  prerelease: false
50
65
  version_requirements: !ruby/object:Gem::Requirement
51
66
  requirements:
67
+ - - "~>"
68
+ - !ruby/object:Gem::Version
69
+ version: '1.0'
52
70
  - - ">="
53
71
  - !ruby/object:Gem::Version
54
72
  version: 1.0.3
@@ -56,6 +74,9 @@ dependencies:
56
74
  name: json-schema
57
75
  requirement: !ruby/object:Gem::Requirement
58
76
  requirements:
77
+ - - "~>"
78
+ - !ruby/object:Gem::Version
79
+ version: '2.5'
59
80
  - - ">="
60
81
  - !ruby/object:Gem::Version
61
82
  version: 2.5.0
@@ -63,6 +84,9 @@ dependencies:
63
84
  prerelease: false
64
85
  version_requirements: !ruby/object:Gem::Requirement
65
86
  requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '2.5'
66
90
  - - ">="
67
91
  - !ruby/object:Gem::Version
68
92
  version: 2.5.0