esi-utils-bvv 0.1.0 → 0.1.1

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: d1644144d86b39a2d80b31402534fb12343a42b2
4
- data.tar.gz: c645e25e666d8720a6e79860569630043393e40b
3
+ metadata.gz: 721ec43d7544b384b2eefb643265f9297c2f0828
4
+ data.tar.gz: 4112d15b22ac7a5e9293e2d1efcbe0e81bf73550
5
5
  SHA512:
6
- metadata.gz: 320f53923a69d37d66eb6926cf4c649069f676259414517d3b79ec55412d1644648b2f1541e2cc6a15b5137a61b44ba2a0538af083e54f97674823775bca0168
7
- data.tar.gz: 9401ca68d03507ffff6c20709edf343003d1ec3f282b898e2d4e1fb2aa0023774736765dfd1b07cd9b6284243ae24ed8c251c362526178d931432c176b53d42d
6
+ metadata.gz: 6b1edf6378608de30b8d9752ad8c0b4784f2fff3f05c7b4f940b5bb5cf479ebd4a14eaa32b3e57225dfc304d08d9f8111137ffe7a74f9d8369040f54e94016b9
7
+ data.tar.gz: 0ce641c80e98a226ee0ab5c78fc339491f148399d8fbc4ea576e2d7c40e48bc04183e1967ffac9e0071325e3229ca5647cf4ff5a86e2d4029c8e7d6237e8955d
data/.rubocop.yml CHANGED
@@ -3,3 +3,7 @@ AllCops:
3
3
  DisplayCopNames: true
4
4
  DisplayStyleGuide: true
5
5
  ExtraDetails: true
6
+
7
+ # Give us a little more leeway on method lengths
8
+ Metrics/MethodLength:
9
+ Max: 15
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- esi-utils-bvv (0.1.0)
4
+ esi-utils-bvv (0.1.1)
5
5
  esi-client-bvv (~> 1.0.4)
6
6
  ffi (= 1.9.21)
7
7
 
@@ -12,6 +12,7 @@ module ESIUtils
12
12
  def initialize
13
13
  super
14
14
  @seen_warnings = Set.new
15
+ @delay_times = [0, 0.5, 1, 2, 5, 15].freeze
15
16
  end
16
17
 
17
18
  def log_warning_header(path, headers)
@@ -21,13 +22,66 @@ module ESIUtils
21
22
  # Only notify about a given (genericised) path once
22
23
  return if @seen_warnings.include?(g_path)
23
24
  @seen_warnings.add(g_path)
24
- puts("Warning: '#{warning}' on path '#{g_path}")
25
+ puts("Warning: '#{warning}' on path '#{g_path}'")
25
26
  end
26
27
 
28
+ #
29
+ # Does the given HTTP status code represent something
30
+ # that we should retry?
31
+ #
32
+ # 420 Error Limited
33
+ # 502 Bad Gateway
34
+ # 503 Service Unavailable
35
+ # 504 Gateway Timeout
36
+ #
37
+ def retry_status?(code)
38
+ case code
39
+ when 420, 502, 503, 504
40
+ true
41
+ else
42
+ false
43
+ end
44
+ end
45
+
46
+ #
47
+ # Can we retry?
48
+ #
49
+ # Based on the details of the APIError exception along
50
+ # with an array of remaining retry delays.
51
+ #
52
+ # If retrying is possible, the result is a number of seconds
53
+ # to delay before performing the next attempt.
54
+ #
55
+ def can_retry?(api_error, delays)
56
+ # Can't retry if we have exhausted our list of retry delays.
57
+ return false if delays.empty?
58
+ # Only certain status codes are retryable.
59
+ return false unless retry_status?(api_error.code)
60
+ # Peel off a time to delay for before retrying.
61
+ delays.shift
62
+ end
63
+
64
+ #
65
+ # Customised call_api, which wraps itself around the one
66
+ # provided by the Swagger generated code.
67
+ #
68
+ # Adds:
69
+ #
70
+ # * Logging of warning headers when the API is versioned.
71
+ # * Automatic retrying of temporary failures.
72
+ #
27
73
  def call_api(http_method, path, opts = {})
28
- data, code, headers = super(http_method, path, opts)
29
- log_warning_header(path, headers)
30
- [data, code, headers]
74
+ delays = @delay_times.dup
75
+ begin
76
+ data, code, headers = super(http_method, path, opts)
77
+ log_warning_header(path, headers)
78
+ [data, code, headers]
79
+ rescue ESI::ApiError => api_error
80
+ raise unless (secs = can_retry?(api_error, delays))
81
+ puts("Retrying #{http_method} on '#{path}' after #{secs}")
82
+ sleep(secs)
83
+ retry
84
+ end
31
85
  end
32
86
  end
33
87
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ESIUtils
4
- VERSION = '0.1.0'
4
+ VERSION = '0.1.1'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: esi-utils-bvv
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bora Vyvorant