idlc-sdk-core 1.1.4 → 1.1.5

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: 24e3ab24085edb47e4855fbf73b1c1cf306f4cbfc039700b8ca07139d2487801
4
- data.tar.gz: 0f4a97d8a41525f892eb9b6951a3ec3bb2745e3b3ffd972b36a072259138c4b3
3
+ metadata.gz: 5f359eccf2136e9e844b00d631b71ba4d53bc27ea3b8867f2894278283802f06
4
+ data.tar.gz: 6b700d3b4184376a94fd512ee85b360bc6d0a5f184800f01a85b899adbe28e41
5
5
  SHA512:
6
- metadata.gz: bcdb41605d8fd9db175ca0cde2eb5059795eb4803972eb5cea241d69c1d99544000c0550fb35531c8f0ec85dcb196dcbfb828b6a23d6748895ff48fec3ca544d
7
- data.tar.gz: 8246197bd86dae9c11edbd353368c20d147bc9f38a7ca142dfec240d4043a0b3439da8fcc78534c3a7d0fb225d2ec776708b83434f777597ca1f1c8c996d0f7a
6
+ metadata.gz: 7fcf3e008ac4ddcff58db39eadf4973e7bdb9e1534d7532e3113873de676b6e37ab103f910556fbea96567b0fc29e82a64401c1730590c9e647fa5daf143f114
7
+ data.tar.gz: 93d7c9a0373f20656f86fb9b8cbc6c5f0e0661db045e348779bea60b3070650afb30164759404adc7e6aef88a1de9cf163c90f3c416bb64d4a500bf163f8069c
@@ -48,6 +48,8 @@ module Idlc
48
48
  end
49
49
 
50
50
  class AWSRestClient
51
+ include Helpers
52
+
51
53
  def initialize(credentials= {
52
54
  access_key_id: ENV['AWS_ACCESS_KEY_ID'],
53
55
  secret_access_key: ENV['AWS_SECRET_ACCESS_KEY'],
@@ -68,17 +70,40 @@ module Idlc
68
70
  body = ''
69
71
  body = request['body'].to_json if request['body']
70
72
 
71
- resp = send_signed_request(
72
- request['method'],
73
- "#{endpoint.strip}#{request['path']}",
74
- body
75
- )
73
+ retries = 0
74
+ max_retries = 5
75
+ sleep_time = 5
76
+ exp_backoff = 2
77
+ result = nil
76
78
 
77
- # if request has 'outfile' param, write response to file
78
- to_file(resp, request['outfile']) if request['outfile']
79
+ loop do
80
+ begin
81
+ resp = send_signed_request(
82
+ request['method'],
83
+ "#{endpoint.strip}#{request['path']}",
84
+ body
85
+ )
86
+
87
+ result = JSON.parse(resp.body)
88
+ message = "status: #{resp.code}, message: #{result['message']}"
89
+ raise message unless resp.code == '200'
90
+ break
91
+ rescue Exception => e
92
+ break if retries >= max_retries
93
+ retries += 1
94
+ msg("RequestFailed: #{e} - Waiting #{sleep_time}s then retrying... (#{retries} of #{max_retries})")
79
95
 
80
- # return response obj
81
- resp
96
+
97
+ sleep sleep_time
98
+ sleep_time *= exp_backoff # use an exponential backoff when retrying requests
99
+ end
100
+ end
101
+
102
+ # if request has 'outfile' param, write response body to file
103
+ to_file(result, request['outfile']) if request['outfile']
104
+
105
+ # return response body obj
106
+ result
82
107
  end
83
108
 
84
109
  def to_file(obj, filename)
@@ -99,7 +124,6 @@ module Idlc
99
124
  request = http_request(method, path, signature, payload)
100
125
 
101
126
  response = https.request(request)
102
- JSON.parse(response.body)
103
127
  end
104
128
 
105
129
  def set_headers(request, signature)
@@ -1,3 +1,3 @@
1
1
  module Idlc
2
- VERSION = '1.1.4'.freeze
2
+ VERSION = '1.1.5'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: idlc-sdk-core
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.4
4
+ version: 1.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nathan Cazell
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-08-15 00:00:00.000000000 Z
11
+ date: 2018-08-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler