infopark-aws_utils 0.6.1 → 0.7.0

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: 389a880cfba3119750fd2f9e4d2d4e7dad83bf2d
4
- data.tar.gz: e94f340162f3f931053a5186a29a5c1d3235c122
3
+ metadata.gz: '078a203a9cd8bfd2dacafae006a0f6213516b453'
4
+ data.tar.gz: 54cd52b74fb99e9300bde91bcb8b5fc5c45f3cce
5
5
  SHA512:
6
- metadata.gz: b3c0d2703181fc994164109b6a0cc877949dba84b7b8b85fd2ff57f82bf2bd3d2ed69d29814df44f8adb0f5a3113b2b9d97fde9e57cce93c3735645c6f131446
7
- data.tar.gz: e172b609850d7af87d9f94505343446dcab29297ff0f0c185e97e9fd05e85a6305a2579fde8d02768d7ecc8b2db30308cc46653403c877e93a7212f15e5029d3
6
+ metadata.gz: 2fe7638fd74cd1f20e0bf87f9ecc459f169fd4897b435cb84d3b9c68f6920b4c1d45766ea9f923fe8b3d86e1267349ab419c27cf3d046917c7e79eeff1a494aa
7
+ data.tar.gz: 5a9571e4cf734b3a7ebd95df8a84abe0ab344d606fb8f65a40afdf1afa624bd6cb8066784590e0c10ea34535b47e082ea89aa5ab098394f03edc3f79e9e949d7
@@ -7,23 +7,29 @@ module Infopark
7
7
 
8
8
  class << self
9
9
  def gather_all(client, method, **options)
10
- @gather_cache ||= {}
11
- cache_key = [client, method, options]
12
- return @gather_cache[cache_key] if @gather_cache[cache_key]
10
+ unless block_given?
11
+ @gather_cache ||= {}
12
+ cache_key = [client, method, options]
13
+ return @gather_cache[cache_key] if @gather_cache[cache_key]
14
+ end
13
15
 
14
16
  result = []
15
17
  loop do
16
- response = client.send(method, **options)
18
+ response = retry_on_throttle { client.send(method, **options) }
17
19
  key = (response.members - [:next_token, :failures]).first
18
20
  if response.members.include?(:failures) && !response.failures.empty?
19
21
  raise "Failed gathering all #{method}: #{response.failures}"
20
22
  end
21
- result += response[key]
23
+ if block_given?
24
+ response[key].each {|entity| retry_on_throttle { yield entity } }
25
+ else
26
+ result += response[key]
27
+ end
22
28
  unless options[:next_token] = response.members.include?(:next_token) && response.next_token
23
29
  break
24
30
  end
25
31
  end
26
- @gather_cache[cache_key] = result
32
+ @gather_cache[cache_key] = result unless block_given?
27
33
  end
28
34
 
29
35
  def wait_for(progress, client, waiter, delay: 2, max_attempts: 60, **waiter_params)
@@ -46,6 +52,18 @@ module Infopark
46
52
  end
47
53
  )
48
54
  end
55
+
56
+ private
57
+
58
+ def retry_on_throttle
59
+ yield
60
+ rescue => e
61
+ if e.class.name =~ /Throttl/
62
+ sleep 0.1
63
+ retry
64
+ end
65
+ raise
66
+ end
49
67
  end
50
68
 
51
69
  DEV_ACCOUNT_ID = ENV['INFOPARK_AWS_DEV_ACCOUNT_ID'] || self.local_config['dev_account_id']
@@ -1,5 +1,5 @@
1
1
  module Infopark
2
2
  module AwsUtils
3
- VERSION = "0.6.1"
3
+ VERSION = "0.7.0"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: infopark-aws_utils
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.1
4
+ version: 0.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tilo Prütz
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-04-11 00:00:00.000000000 Z
11
+ date: 2018-09-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: aws-sdk-applicationautoscaling