record_store 6.1.1 → 6.1.2

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
  SHA256:
3
- metadata.gz: f7a5da9483eaf8ce4eb82e8d974fefe82f7f481cde945a45ec6ae204b02524dc
4
- data.tar.gz: 51e681688b6cc80c851f801ad00bb07ccf473ea2fb0b1c8a8e722d3cbc2ec196
3
+ metadata.gz: 4d05ecb06f048975b797baa10df042222f03ee4f0b1b5e268afa87e97b16ede6
4
+ data.tar.gz: 4ca96a597c88f5d17df9f85ea50e8743b0cab6fa4d57196447d3808cc22711a6
5
5
  SHA512:
6
- metadata.gz: 502acb53fcef150d5cb5442414c47552fc199efe66012e85d30745ae25c8af326064283c855ba12f4cead5b6f7b09f5a97c0b3bd6a4de1a010bba15664954335
7
- data.tar.gz: 491ee9ff80ccb35ceb7ffbe70776948cd459467df8c213917c08ac6830e249585dbd993849a44e413bd6fc8e38589601eab27601cf3061c9b51abd09a94898a0
6
+ metadata.gz: 98581b53f61499cb2f83d92ae2de4cf132ce2784cf56f8dc81531228f4090995f8e7a5a2c70f0a8fcac0cc5a3bdea29dd5c1d7b6996eef61e416c0c65c6a252d
7
+ data.tar.gz: 8e753593bc358e83f82a0191f07528e14aa793305570afae5fcc865e1bdd97fffb48319fec43642e662c7b62e1070dd3b384464b9ca55a39e2a590fcf0f6738b
@@ -671,7 +671,7 @@ Style/LineEndConcatenation:
671
671
  Style/MethodCallWithoutArgsParentheses:
672
672
  Enabled: true
673
673
 
674
- Style/MethodMissingSuper:
674
+ Lint/MissingSuper:
675
675
  Enabled: true
676
676
 
677
677
  Style/MissingRespondToMissing:
@@ -964,7 +964,7 @@ Lint/UselessAccessModifier:
964
964
  Lint/UselessAssignment:
965
965
  Enabled: true
966
966
 
967
- Lint/UselessComparison:
967
+ Lint/BinaryOperatorWithIdenticalOperands:
968
968
  Enabled: true
969
969
 
970
970
  Lint/UselessElseWithoutRescue:
@@ -128,6 +128,36 @@ module RecordStore
128
128
 
129
129
  dns.getresource(zone_name, Resolv::DNS::Resource::IN::SOA).mname.to_s
130
130
  end
131
+
132
+ def retry_on_connection_errors(
133
+ max_timeouts: 5,
134
+ max_conn_resets: 5,
135
+ delay: 1,
136
+ backoff_multiplier: 2,
137
+ max_backoff: 10
138
+ )
139
+ loop do
140
+ begin
141
+ return yield
142
+ rescue Net::OpenTimeout
143
+ raise if max_timeouts <= 0
144
+ max_timeouts -= 1
145
+
146
+ $stderr.puts("Retrying after a connection timeout")
147
+ rescue Errno::ECONNRESET
148
+ raise if max_conn_resets <= 0
149
+ max_conn_resets -= 1
150
+
151
+ $stderr.puts("Retrying in #{delay}s after a connection reset")
152
+ backoff_sleep(delay)
153
+ delay = [delay * backoff_multiplier, max_backoff].min
154
+ end
155
+ end
156
+ end
157
+
158
+ def backoff_sleep(delay)
159
+ sleep(delay)
160
+ end
131
161
  end
132
162
  end
133
163
  end
@@ -14,19 +14,23 @@ module RecordStore
14
14
 
15
15
  # returns an array of Record objects that match the records which exist in the provider
16
16
  def retrieve_current_records(zone:, stdout: $stdout)
17
- session.zones.all_records(account_id, zone).data.map do |record|
18
- begin
19
- build_from_api(record, zone)
20
- rescue StandardError
21
- stdout.puts "Cannot build record: #{record}"
22
- raise
23
- end
24
- end.compact
17
+ retry_on_connection_errors do
18
+ session.zones.all_records(account_id, zone).data.map do |record|
19
+ begin
20
+ build_from_api(record, zone)
21
+ rescue StandardError
22
+ stdout.puts "Cannot build record: #{record}"
23
+ raise
24
+ end
25
+ end.compact
26
+ end
25
27
  end
26
28
 
27
29
  # Returns an array of the zones managed by provider as strings
28
30
  def zones
29
- session.zones.all_zones(account_id).data.map(&:name)
31
+ retry_on_connection_errors do
32
+ session.zones.all_zones(account_id).data.map(&:name)
33
+ end
30
34
  end
31
35
 
32
36
  private
@@ -60,14 +60,18 @@ module RecordStore
60
60
 
61
61
  # Returns an array of the zones managed by provider as strings
62
62
  def zones
63
- client.zones.map { |zone| zone['zone'] }
63
+ retry_on_connection_errors do
64
+ client.zones.map { |zone| zone['zone'] }
65
+ end
64
66
  end
65
67
 
66
68
  private
67
69
 
68
70
  # Fetches simplified records for the provided zone
69
71
  def records_for_zone(zone)
70
- client.zone(zone)['records']
72
+ retry_on_connection_errors do
73
+ client.zone(zone)['records']
74
+ end
71
75
  end
72
76
 
73
77
  # Creates a new record to the zone. It is expected this call modifies external state.
@@ -4,12 +4,19 @@ require_relative '../provider_utils/rate_limit'
4
4
  # Patch the method which retrieves headers for API rate limit dynamically
5
5
  module NS1::Transport
6
6
  class NetHttp
7
+ X_RATELIMIT_PERIOD = 'x-ratelimit-period'.freeze
8
+ X_RATELIMIT_REMAINING = 'x-ratelimit-remaining'.freeze
9
+
7
10
  def process_response(response)
8
- sleep_time = response.to_hash['x-ratelimit-period'].first.to_i /
9
- [1, response.to_hash['x-ratelimit-remaining'].first.to_i].max.to_f
11
+ response_hash = response.to_hash
12
+
13
+ if response_hash.key?(X_RATELIMIT_PERIOD) && response_hash.key?(X_RATELIMIT_REMAINING)
14
+ sleep_time = response_hash[X_RATELIMIT_PERIOD].first.to_i /
15
+ [1, response_hash[X_RATELIMIT_REMAINING].first.to_i].max.to_f
10
16
 
11
- rate_limit = RateLimit.new('NS1')
12
- rate_limit.sleep_for(sleep_time)
17
+ rate_limit = RateLimit.new('NS1')
18
+ rate_limit.sleep_for(sleep_time)
19
+ end
13
20
 
14
21
  body = JSON.parse(response.body)
15
22
  case response
@@ -1,3 +1,3 @@
1
1
  module RecordStore
2
- VERSION = '6.1.1'.freeze
2
+ VERSION = '6.1.2'.freeze
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: record_store
3
3
  version: !ruby/object:Gem::Version
4
- version: 6.1.1
4
+ version: 6.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Willem van Bergen
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2020-06-11 00:00:00.000000000 Z
12
+ date: 2020-08-18 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: thor