infopark_cloud_connector 6.8.0.444.171626367 → 6.8.0.480.261594408

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,8 +1,17 @@
1
+ module RailsConnector
1
2
  class ContentService
2
3
  DEFAULT_PROTOCOL = 'https'.freeze
3
4
  SOCKET_ERRORS = [EOFError, IOError, Errno::ECONNABORTED, Errno::ECONNRESET,
4
5
  Errno::EPIPE, Errno::EINVAL].freeze
5
6
 
7
+ class RateLimitExceeded < StandardError
8
+ def initialize(retry_after)
9
+ @retry_after = retry_after
10
+ end
11
+
12
+ attr_reader :retry_after
13
+ end
14
+
6
15
  def self.query(path, payload)
7
16
  retry_once_on_socket_error do
8
17
  ConnectionManager.ensure_started(uri)
@@ -23,6 +32,9 @@ class ContentService
23
32
  ConnectionManager.ensure_finished
24
33
  retried = true
25
34
  retry
35
+ rescue RateLimitExceeded => e
36
+ sleep (e.retry_after || 0.8).to_f
37
+ retry
26
38
  end
27
39
  end
28
40
 
@@ -36,6 +48,8 @@ class ContentService
36
48
  def handle_response(response)
37
49
  if response.code.first == '2'
38
50
  MultiJson.load(response.body)
51
+ elsif response.code == "429"
52
+ raise RateLimitExceeded.new(response["Retry-After"])
39
53
  else
40
54
  raise "Server responded with status code #{response.code}"
41
55
  end
@@ -113,3 +127,4 @@ class ContentService
113
127
  end
114
128
  end
115
129
  end
130
+ end
@@ -1,3 +1,4 @@
1
+ # encoding: UTF-8
1
2
  module RailsConnector
2
3
  # Provides an enumerator for iterating over obj search results and retrieving obj instances.
3
4
  # This is done using the {http://ruby-doc.org/core-1.8.7/Enumerable.html <code>Enumerable</code> mixin},
@@ -2,6 +2,50 @@ require 'rest_client'
2
2
 
3
3
  module RailsConnector
4
4
 
5
+ class ContentServiceObjQueries
6
+ def initialize(queries)
7
+ @queries = queries
8
+ @open_queries = queries.dup
9
+ @results = {}
10
+ end
11
+
12
+ def open_queries
13
+ @open_queries[0..99]
14
+ end
15
+
16
+ def handle_response(response)
17
+ objs = {}
18
+ response["objs"].each do |obj|
19
+ objs[obj["_id"].first] = obj
20
+ end
21
+
22
+ queries_to_delete = []
23
+ response["results"].each_with_index do |response, i|
24
+ query = @open_queries[i]
25
+ if response["continuation_handle"]
26
+ query[:continuation_handle] = response["continuation_handle"]
27
+ else
28
+ queries_to_delete << i
29
+ end
30
+ result = (@results[query.__id__] ||= [])
31
+ response["refs"].each do |obj_ref|
32
+ id = obj_ref["id"]
33
+ # TODO fetch missing ObjData from Service
34
+ result << (objs[id] or raise "Data for Obj with id #{id} missing!")
35
+ end
36
+ end
37
+ queries_to_delete.reverse_each {|i| @open_queries.delete_at(i) }
38
+ end
39
+
40
+ def results
41
+ @queries.map {|query| @results[query.__id__] || [] }
42
+ end
43
+
44
+ def finished?
45
+ open_queries.empty?
46
+ end
47
+ end
48
+
5
49
  # connects the cloud connector to the connector service
6
50
  class ServiceCmsBackend < CmsBackend
7
51
  CACHE_PREFIX = 'v1'
@@ -97,28 +141,16 @@ module RailsConnector
97
141
  "cms_load.rails_connector", :name => "Obj Load", :index => index, :keys => keys
98
142
  ) do
99
143
  @query_counter += 1
100
- raw_data = ContentService.query(
101
- "objs/query",
102
- :queries => keys.map do |key|
103
- { :type => index, :param => key }
104
- end,
105
- :workspace_id => workspace_data.id,
106
- :revision_id => workspace_data.revision_id
107
- )
108
-
109
- objs = {}
110
- raw_data["objs"].each do |obj|
111
- objs[obj["_id"].first] = obj
112
- end
113
-
114
- raw_data["results"].map do |query|
115
- query["refs"].map do |obj_ref|
116
- id = obj_ref["id"]
117
-
118
- # TODO fetch missing ObjData from Service
119
- objs[id] or raise "Data for Obj with id #{id} missing!"
120
- end
144
+ queries = ContentServiceObjQueries.new(keys.map {|key| {:type => index, :param => key} })
145
+ until queries.finished?
146
+ queries.handle_response(ContentService.query(
147
+ "objs/query",
148
+ :queries => queries.open_queries,
149
+ :workspace_id => workspace_data.id,
150
+ :revision_id => workspace_data.revision_id
151
+ ))
121
152
  end
153
+ queries.results
122
154
  end
123
155
  end
124
156
 
metadata CHANGED
@@ -1,15 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: infopark_cloud_connector
3
3
  version: !ruby/object:Gem::Version
4
- hash: 343251185
4
+ hash: 523189551
5
5
  prerelease:
6
6
  segments:
7
7
  - 6
8
8
  - 8
9
9
  - 0
10
- - 444
11
- - 171626367
12
- version: 6.8.0.444.171626367
10
+ - 480
11
+ - 261594408
12
+ version: 6.8.0.480.261594408
13
13
  platform: ruby
14
14
  authors:
15
15
  - Infopark AG
@@ -17,7 +17,7 @@ autorequire:
17
17
  bindir: bin
18
18
  cert_chain: []
19
19
 
20
- date: 2012-12-06 00:00:00 +01:00
20
+ date: 2012-12-12 00:00:00 +01:00
21
21
  default_executable:
22
22
  dependencies:
23
23
  - !ruby/object:Gem::Dependency
@@ -57,14 +57,14 @@ dependencies:
57
57
  requirements:
58
58
  - - "="
59
59
  - !ruby/object:Gem::Version
60
- hash: 343251185
60
+ hash: 523189551
61
61
  segments:
62
62
  - 6
63
63
  - 8
64
64
  - 0
65
- - 444
66
- - 171626367
67
- version: 6.8.0.444.171626367
65
+ - 480
66
+ - 261594408
67
+ version: 6.8.0.480.261594408
68
68
  version_requirements: *id003
69
69
  name: kvom
70
70
  prerelease: false