infopark_cloud_connector 6.8.2.7.128454143 → 6.8.2.36.82613853

Sign up to get free protection for your applications and to get access to all the features.
@@ -12,15 +12,45 @@ class ContentService
12
12
  attr_reader :retry_after
13
13
  end
14
14
 
15
- def self.query(path, payload)
16
- retry_once_on_socket_error do
17
- ConnectionManager.ensure_started(uri)
18
- request = build_request(path, payload)
19
- handle_response(ConnectionManager.connection.request(request))
15
+ class MaxSleepTimeReached < StandardError
16
+ end
17
+
18
+ class Delay
19
+ def initialize
20
+ @sleep_count = 0
21
+ @total_sleep_time = 0
22
+ end
23
+
24
+ def next_sleep_time(min_sleep = 0)
25
+ sleep_time = [2 ** @sleep_count * 0.5, min_sleep.to_f].max
26
+ @total_sleep_time += sleep_time
27
+ raise MaxSleepTimeReached if @total_sleep_time > 40
28
+ @sleep_count += 1
29
+ sleep_time
20
30
  end
21
31
  end
22
32
 
23
33
  class << self
34
+ @next_request_not_before = nil
35
+
36
+ def query(path, payload)
37
+ retry_once_on_socket_error do
38
+ retry_until_timeout_on_rate_limit_exceeded do
39
+ ConnectionManager.ensure_started(uri)
40
+ request = build_request(path, payload)
41
+ if @next_request_not_before && @next_request_not_before > (now = Time.now)
42
+ sleep @next_request_not_before - now
43
+ end
44
+ handle_response(ConnectionManager.connection.request(request))
45
+ end
46
+ end
47
+ end
48
+
49
+ # for tests only
50
+ def forget_retry_after
51
+ @next_request_not_before = nil
52
+ end
53
+
24
54
  private
25
55
 
26
56
  def retry_once_on_socket_error
@@ -32,8 +62,19 @@ class ContentService
32
62
  ConnectionManager.ensure_finished
33
63
  retried = true
34
64
  retry
65
+ end
66
+ end
67
+
68
+ def retry_until_timeout_on_rate_limit_exceeded
69
+ delay = Delay.new
70
+ begin
71
+ yield
35
72
  rescue RateLimitExceeded => e
36
- sleep (e.retry_after || 0.8).to_f
73
+ begin
74
+ sleep delay.next_sleep_time(e.retry_after)
75
+ rescue MaxSleepTimeReached
76
+ raise BackendNotAvailable.new('rate limit exceeded', 429)
77
+ end
37
78
  retry
38
79
  end
39
80
  end
@@ -47,6 +88,8 @@ class ContentService
47
88
 
48
89
  def handle_response(response)
49
90
  if response.code.first == '2'
91
+ retry_after = response["Retry-After"]
92
+ @next_request_not_before = retry_after ? Time.now + retry_after.to_f : nil
50
93
  MultiJson.load(response.body)
51
94
  elsif response.code == "429"
52
95
  raise RateLimitExceeded.new(response["Retry-After"])
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: infopark_cloud_connector
3
3
  version: !ruby/object:Gem::Version
4
- version: 6.8.2.7.128454143
4
+ version: 6.8.2.36.82613853
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-01-30 00:00:00.000000000 Z
12
+ date: 2013-01-31 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: aws-sdk
@@ -50,7 +50,7 @@ dependencies:
50
50
  requirements:
51
51
  - - '='
52
52
  - !ruby/object:Gem::Version
53
- version: 6.8.2.7.128454143
53
+ version: 6.8.2.36.82613853
54
54
  type: :runtime
55
55
  prerelease: false
56
56
  version_requirements: !ruby/object:Gem::Requirement
@@ -58,7 +58,7 @@ dependencies:
58
58
  requirements:
59
59
  - - '='
60
60
  - !ruby/object:Gem::Version
61
- version: 6.8.2.7.128454143
61
+ version: 6.8.2.36.82613853
62
62
  description: The Cloud Connector for Infopark CMS Fiona enables you to develop modern,
63
63
  dynamic Web 2.0 applications using Ruby on Rails and at the same time display CMS
64
64
  managed content.
@@ -142,7 +142,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
142
142
  version: '0'
143
143
  segments:
144
144
  - 0
145
- hash: 903498323
145
+ hash: -1009000627
146
146
  required_rubygems_version: !ruby/object:Gem::Requirement
147
147
  none: false
148
148
  requirements: