alephant-broker 3.2.0 → 3.3.0

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
  SHA1:
3
- metadata.gz: 70103bf930de096da5829872125d161af9a9d17a
4
- data.tar.gz: 95a5865427ae88a3b456f1f38e0ae7583f309f37
3
+ metadata.gz: bad508555563294c2782af87c53618b28b78834b
4
+ data.tar.gz: ce942ad7a32671222334f7883d772ea5a3135467
5
5
  SHA512:
6
- metadata.gz: 51e92cb40072fbe3088e08495fabfc90e4140255572ac8ae0a720398c8e25ed4d5b87e86bbaa850c5b276b83c4e2640debf35917a7bd4b496c158a252207d0f0
7
- data.tar.gz: a5fae01f6f1d2463e9dc028b0850cdbf7c767853aaf0787acd522bf626739c77863e79b130d2aa16723fc9b82dab004987ac917c15a65eec34bab8dd40468a61
6
+ metadata.gz: baf72da1f88eb8dec96b3e41af92538325a0cbcb4a796861bc292e237d856a6710ce171af01270e036f5e64a6cff415508c7a3b9e6ca44a1905707958d38d1a9
7
+ data.tar.gz: 5e8768a0475a5a5e8358f4e6aad32019ffa4648f24f77de89e3567666490403256b9069fce804d12e2713592fb45a9ca06340add5cf9e0a256e57561729ad14c
data/README.md CHANGED
@@ -125,6 +125,16 @@ run Alephant::Broker::Application.new(
125
125
  )
126
126
  ```
127
127
 
128
+ ### Cache version number
129
+
130
+ The broker looks for a configuration value `elasticache_cache_version` and if it exists it uses it to construct the cache key.
131
+ This allows the cache to be busted if the data in the cache changes, or for any other reason that it needs to be invalidated.
132
+
133
+ This version is added as a header to the response in the following format:
134
+
135
+ `X-Cache-Version: {CACHE_VERSION}`
136
+
137
+
128
138
  ## Contributing
129
139
 
130
140
  1. [Fork it!]( http://github.com/bbc-news/alephant-broker/fork)
@@ -2,11 +2,9 @@ require 'alephant/broker/version'
2
2
  require 'alephant/broker/request'
3
3
  require 'alephant/broker/environment'
4
4
  require 'alephant/broker'
5
- require 'ostruct'
6
5
 
7
6
  module Alephant
8
7
  module Broker
9
- @@poll = true
10
8
 
11
9
  def self.handle(load_strategy, env)
12
10
  Request::Handler.process(load_strategy, env)
@@ -20,14 +18,6 @@ module Alephant
20
18
  @@configuration = c
21
19
  end
22
20
 
23
- def self.poll?
24
- @@poll
25
- end
26
-
27
- def self.poll=(state)
28
- @@poll = state
29
- end
30
-
31
21
  class Application
32
22
  attr_reader :load_strategy
33
23
 
@@ -37,11 +27,7 @@ module Alephant
37
27
  end
38
28
 
39
29
  def call(env)
40
- if ::Alephant::Broker.poll?
41
- send response_for(environment_for(env))
42
- else
43
- send stop_poll_response
44
- end
30
+ send response_for(environment_for(env))
45
31
  end
46
32
 
47
33
  def environment_for(env)
@@ -61,23 +47,6 @@ module Alephant
61
47
  ]
62
48
  ]
63
49
  end
64
-
65
- private
66
-
67
- def stop_poll_response
68
- response = OpenStruct.new(
69
- :status => 420,
70
- :content => "Stopped polling",
71
- :cached => false,
72
- :version => 0,
73
- :sequence => 0,
74
- :headers => {
75
- "Content-Type" => "plain/text",
76
- "X-Cached" => "false",
77
- "X-Stop-Polling" => "true"
78
- }
79
- )
80
- end
81
50
  end
82
51
  end
83
52
  end
@@ -22,7 +22,8 @@ module Alephant
22
22
 
23
23
  def get(key, &block)
24
24
  begin
25
- result = @@client.get(versioned(key))
25
+ key = versioned(key)
26
+ result = @@client.get key
26
27
  logger.info("Broker::Cache::Client#get key: #{key} - #{result ? 'hit' : 'miss'}")
27
28
  logger.metric(:name => "BrokerCacheClientGetKeyMiss", :unit => "Count", :value => 1) unless result
28
29
  result ? result : set(key, block.call)
@@ -27,8 +27,6 @@ module Alephant
27
27
  def headers
28
28
  {
29
29
  'Content-Type' => data[:content_type].to_s,
30
- 'X-Version' => meta.version.to_s,
31
- 'X-Cached' => meta.cached.to_s
32
30
  }.merge(data[:headers] || {})
33
31
  end
34
32
 
@@ -2,23 +2,11 @@ module Alephant
2
2
  module Broker
3
3
  class ComponentMeta
4
4
  attr_reader :id, :options, :batch_id
5
- attr_accessor :cached
6
5
 
7
6
  def initialize(id, batch_id, options)
8
7
  @id = id
9
8
  @batch_id = batch_id
10
9
  @options = convert_keys(options || {})
11
- @cached = true
12
- end
13
-
14
- def cache_key
15
- "#{id}/#{opts_hash}/#{version}"
16
- end
17
-
18
- def version
19
- Broker.config.fetch(
20
- 'elasticache_cache_version', 'not available'
21
- ).to_s
22
10
  end
23
11
 
24
12
  def key
@@ -29,27 +17,19 @@ module Alephant
29
17
  Crimp.signature options
30
18
  end
31
19
 
20
+ def component_key
21
+ "#{id}/#{opts_hash}"
22
+ end
23
+
32
24
  private
33
25
 
34
26
  def convert_keys(hash)
35
27
  Hash[ hash.map { |k, v| [k.to_sym, v] } ]
36
28
  end
37
29
 
38
- def component_key
39
- "#{id}/#{opts_hash}"
40
- end
41
-
42
30
  def renderer_key
43
31
  "#{batch_id}/#{opts_hash}"
44
32
  end
45
-
46
- def headers(data)
47
- {
48
- 'Content-Type' => data[:content_type].to_s,
49
- 'X-Version' => version.to_s,
50
- 'X-Cached' => cached.to_s
51
- }.merge(data[:headers] || {})
52
- end
53
33
  end
54
34
  end
55
35
  end
@@ -9,6 +9,11 @@ module Alephant
9
9
  module S3
10
10
  class Base
11
11
  include Logger
12
+ attr_accessor :cached
13
+
14
+ def initialize
15
+ @cached = true
16
+ end
12
17
 
13
18
  def load(component_meta)
14
19
  add_s3_headers(
@@ -23,7 +28,7 @@ module Alephant
23
28
  )
24
29
  add_s3_headers(
25
30
  cache.set(
26
- component_meta.cache_key,
31
+ cache_key(component_meta),
27
32
  retrieve_object(component_meta)
28
33
  ),
29
34
  component_meta
@@ -36,6 +41,10 @@ module Alephant
36
41
  Hash.new
37
42
  end
38
43
 
44
+ def cache_key(component_meta)
45
+ component_meta.component_key
46
+ end
47
+
39
48
  private
40
49
 
41
50
  def s3_path(component_meta)
@@ -53,7 +62,7 @@ module Alephant
53
62
  end
54
63
 
55
64
  def retrieve_object(component_meta)
56
- component_meta.cached = false
65
+ cached = false
57
66
  s3.get s3_path(component_meta)
58
67
  rescue AWS::S3::Errors::NoSuchKey, InvalidCacheKey
59
68
  logger.metric(
@@ -65,7 +74,7 @@ module Alephant
65
74
  end
66
75
 
67
76
  def cache_object(component_meta)
68
- cache.get(component_meta.cache_key) do
77
+ cache.get cache_key(component_meta) do
69
78
  retrieve_object component_meta
70
79
  end
71
80
  end
@@ -82,6 +91,13 @@ module Alephant
82
91
  Broker.config[:lookup_table_name]
83
92
  )
84
93
  end
94
+
95
+ def headers(component_meta)
96
+ {
97
+ 'X-Cache-Version' => Broker.config['elasticache_cache_version'].to_s,
98
+ 'X-Cached' => cached.to_s
99
+ }
100
+ end
85
101
  end
86
102
  end
87
103
  end
@@ -9,10 +9,6 @@ module Alephant
9
9
  sequencer.get_last_seen component_meta.key
10
10
  end
11
11
 
12
- def headers(component_meta)
13
- { "X-Sequence" => sequence(component_meta).to_s }
14
- end
15
-
16
12
  def s3_path(component_meta)
17
13
  lookup.read(
18
14
  component_meta.id,
@@ -28,6 +24,16 @@ module Alephant
28
24
  Broker.config[:sequencer_table_name], nil
29
25
  )
30
26
  end
27
+
28
+ def cache_key(component_meta)
29
+ "#{super(component_meta)}/#{sequence(component_meta)}"
30
+ end
31
+
32
+ def headers(component_meta)
33
+ {
34
+ "X-Sequence" => sequence(component_meta).to_s
35
+ }.merge(super(component_meta))
36
+ end
31
37
  end
32
38
  end
33
39
  end
@@ -1,5 +1,5 @@
1
1
  module Alephant
2
2
  module Broker
3
- VERSION = "3.2.0"
3
+ VERSION = "3.3.0"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,281 +1,281 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: alephant-broker
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.2.0
4
+ version: 3.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Steven Jack
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-02-10 00:00:00.000000000 Z
11
+ date: 2015-02-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
+ name: rspec
15
+ version_requirements: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
14
20
  requirement: !ruby/object:Gem::Requirement
15
21
  requirements:
16
22
  - - '>='
17
23
  - !ruby/object:Gem::Version
18
24
  version: '0'
19
- name: rspec
20
25
  prerelease: false
21
26
  type: :development
27
+ - !ruby/object:Gem::Dependency
28
+ name: rspec-nc
22
29
  version_requirements: !ruby/object:Gem::Requirement
23
30
  requirements:
24
31
  - - '>='
25
32
  - !ruby/object:Gem::Version
26
33
  version: '0'
27
- - !ruby/object:Gem::Dependency
28
34
  requirement: !ruby/object:Gem::Requirement
29
35
  requirements:
30
36
  - - '>='
31
37
  - !ruby/object:Gem::Version
32
38
  version: '0'
33
- name: rspec-nc
34
39
  prerelease: false
35
40
  type: :development
41
+ - !ruby/object:Gem::Dependency
42
+ name: guard
36
43
  version_requirements: !ruby/object:Gem::Requirement
37
44
  requirements:
38
45
  - - '>='
39
46
  - !ruby/object:Gem::Version
40
47
  version: '0'
41
- - !ruby/object:Gem::Dependency
42
48
  requirement: !ruby/object:Gem::Requirement
43
49
  requirements:
44
50
  - - '>='
45
51
  - !ruby/object:Gem::Version
46
52
  version: '0'
47
- name: guard
48
53
  prerelease: false
49
54
  type: :development
55
+ - !ruby/object:Gem::Dependency
56
+ name: guard-rspec
50
57
  version_requirements: !ruby/object:Gem::Requirement
51
58
  requirements:
52
59
  - - '>='
53
60
  - !ruby/object:Gem::Version
54
61
  version: '0'
55
- - !ruby/object:Gem::Dependency
56
62
  requirement: !ruby/object:Gem::Requirement
57
63
  requirements:
58
64
  - - '>='
59
65
  - !ruby/object:Gem::Version
60
66
  version: '0'
61
- name: guard-rspec
62
67
  prerelease: false
63
68
  type: :development
69
+ - !ruby/object:Gem::Dependency
70
+ name: pry
64
71
  version_requirements: !ruby/object:Gem::Requirement
65
72
  requirements:
66
73
  - - '>='
67
74
  - !ruby/object:Gem::Version
68
75
  version: '0'
69
- - !ruby/object:Gem::Dependency
70
76
  requirement: !ruby/object:Gem::Requirement
71
77
  requirements:
72
78
  - - '>='
73
79
  - !ruby/object:Gem::Version
74
80
  version: '0'
75
- name: pry
76
81
  prerelease: false
77
82
  type: :development
83
+ - !ruby/object:Gem::Dependency
84
+ name: pry-remote
78
85
  version_requirements: !ruby/object:Gem::Requirement
79
86
  requirements:
80
87
  - - '>='
81
88
  - !ruby/object:Gem::Version
82
89
  version: '0'
83
- - !ruby/object:Gem::Dependency
84
90
  requirement: !ruby/object:Gem::Requirement
85
91
  requirements:
86
92
  - - '>='
87
93
  - !ruby/object:Gem::Version
88
94
  version: '0'
89
- name: pry-remote
90
95
  prerelease: false
91
96
  type: :development
97
+ - !ruby/object:Gem::Dependency
98
+ name: pry-nav
92
99
  version_requirements: !ruby/object:Gem::Requirement
93
100
  requirements:
94
101
  - - '>='
95
102
  - !ruby/object:Gem::Version
96
103
  version: '0'
97
- - !ruby/object:Gem::Dependency
98
104
  requirement: !ruby/object:Gem::Requirement
99
105
  requirements:
100
106
  - - '>='
101
107
  - !ruby/object:Gem::Version
102
108
  version: '0'
103
- name: pry-nav
104
109
  prerelease: false
105
110
  type: :development
111
+ - !ruby/object:Gem::Dependency
112
+ name: rake-rspec
106
113
  version_requirements: !ruby/object:Gem::Requirement
107
114
  requirements:
108
115
  - - '>='
109
116
  - !ruby/object:Gem::Version
110
- version: '0'
111
- - !ruby/object:Gem::Dependency
117
+ version: 0.0.2
112
118
  requirement: !ruby/object:Gem::Requirement
113
119
  requirements:
114
120
  - - '>='
115
121
  - !ruby/object:Gem::Version
116
122
  version: 0.0.2
117
- name: rake-rspec
118
123
  prerelease: false
119
124
  type: :development
125
+ - !ruby/object:Gem::Dependency
126
+ name: bundler
120
127
  version_requirements: !ruby/object:Gem::Requirement
121
128
  requirements:
122
- - - '>='
129
+ - - ~>
123
130
  - !ruby/object:Gem::Version
124
- version: 0.0.2
125
- - !ruby/object:Gem::Dependency
131
+ version: '1.5'
126
132
  requirement: !ruby/object:Gem::Requirement
127
133
  requirements:
128
134
  - - ~>
129
135
  - !ruby/object:Gem::Version
130
136
  version: '1.5'
131
- name: bundler
132
137
  prerelease: false
133
138
  type: :development
139
+ - !ruby/object:Gem::Dependency
140
+ name: rake
134
141
  version_requirements: !ruby/object:Gem::Requirement
135
142
  requirements:
136
- - - ~>
143
+ - - '>='
137
144
  - !ruby/object:Gem::Version
138
- version: '1.5'
139
- - !ruby/object:Gem::Dependency
145
+ version: '0'
140
146
  requirement: !ruby/object:Gem::Requirement
141
147
  requirements:
142
148
  - - '>='
143
149
  - !ruby/object:Gem::Version
144
150
  version: '0'
145
- name: rake
146
151
  prerelease: false
147
152
  type: :development
153
+ - !ruby/object:Gem::Dependency
154
+ name: rack-test
148
155
  version_requirements: !ruby/object:Gem::Requirement
149
156
  requirements:
150
157
  - - '>='
151
158
  - !ruby/object:Gem::Version
152
159
  version: '0'
153
- - !ruby/object:Gem::Dependency
154
160
  requirement: !ruby/object:Gem::Requirement
155
161
  requirements:
156
162
  - - '>='
157
163
  - !ruby/object:Gem::Version
158
164
  version: '0'
159
- name: rack-test
160
165
  prerelease: false
161
166
  type: :development
167
+ - !ruby/object:Gem::Dependency
168
+ name: alephant-lookup
162
169
  version_requirements: !ruby/object:Gem::Requirement
163
170
  requirements:
164
171
  - - '>='
165
172
  - !ruby/object:Gem::Version
166
173
  version: '0'
167
- - !ruby/object:Gem::Dependency
168
174
  requirement: !ruby/object:Gem::Requirement
169
175
  requirements:
170
176
  - - '>='
171
177
  - !ruby/object:Gem::Version
172
178
  version: '0'
173
- name: alephant-lookup
174
179
  prerelease: false
175
180
  type: :runtime
181
+ - !ruby/object:Gem::Dependency
182
+ name: alephant-cache
176
183
  version_requirements: !ruby/object:Gem::Requirement
177
184
  requirements:
178
185
  - - '>='
179
186
  - !ruby/object:Gem::Version
180
187
  version: '0'
181
- - !ruby/object:Gem::Dependency
182
188
  requirement: !ruby/object:Gem::Requirement
183
189
  requirements:
184
190
  - - '>='
185
191
  - !ruby/object:Gem::Version
186
192
  version: '0'
187
- name: alephant-cache
188
193
  prerelease: false
189
194
  type: :runtime
195
+ - !ruby/object:Gem::Dependency
196
+ name: alephant-logger
190
197
  version_requirements: !ruby/object:Gem::Requirement
191
198
  requirements:
192
- - - '>='
199
+ - - ~>
193
200
  - !ruby/object:Gem::Version
194
201
  version: '0'
195
- - !ruby/object:Gem::Dependency
196
202
  requirement: !ruby/object:Gem::Requirement
197
203
  requirements:
198
204
  - - ~>
199
205
  - !ruby/object:Gem::Version
200
206
  version: '0'
201
- name: alephant-logger
202
207
  prerelease: false
203
208
  type: :runtime
209
+ - !ruby/object:Gem::Dependency
210
+ name: alephant-sequencer
204
211
  version_requirements: !ruby/object:Gem::Requirement
205
212
  requirements:
206
- - - ~>
213
+ - - '>='
207
214
  - !ruby/object:Gem::Version
208
215
  version: '0'
209
- - !ruby/object:Gem::Dependency
210
216
  requirement: !ruby/object:Gem::Requirement
211
217
  requirements:
212
218
  - - '>='
213
219
  - !ruby/object:Gem::Version
214
220
  version: '0'
215
- name: alephant-sequencer
216
221
  prerelease: false
217
222
  type: :runtime
223
+ - !ruby/object:Gem::Dependency
224
+ name: dalli-elasticache
218
225
  version_requirements: !ruby/object:Gem::Requirement
219
226
  requirements:
220
227
  - - '>='
221
228
  - !ruby/object:Gem::Version
222
229
  version: '0'
223
- - !ruby/object:Gem::Dependency
224
230
  requirement: !ruby/object:Gem::Requirement
225
231
  requirements:
226
232
  - - '>='
227
233
  - !ruby/object:Gem::Version
228
234
  version: '0'
229
- name: dalli-elasticache
230
235
  prerelease: false
231
236
  type: :runtime
237
+ - !ruby/object:Gem::Dependency
238
+ name: pmap
232
239
  version_requirements: !ruby/object:Gem::Requirement
233
240
  requirements:
234
241
  - - '>='
235
242
  - !ruby/object:Gem::Version
236
243
  version: '0'
237
- - !ruby/object:Gem::Dependency
238
244
  requirement: !ruby/object:Gem::Requirement
239
245
  requirements:
240
246
  - - '>='
241
247
  - !ruby/object:Gem::Version
242
248
  version: '0'
243
- name: pmap
244
249
  prerelease: false
245
250
  type: :runtime
251
+ - !ruby/object:Gem::Dependency
252
+ name: faraday
246
253
  version_requirements: !ruby/object:Gem::Requirement
247
254
  requirements:
248
255
  - - '>='
249
256
  - !ruby/object:Gem::Version
250
257
  version: '0'
251
- - !ruby/object:Gem::Dependency
252
258
  requirement: !ruby/object:Gem::Requirement
253
259
  requirements:
254
260
  - - '>='
255
261
  - !ruby/object:Gem::Version
256
262
  version: '0'
257
- name: faraday
258
263
  prerelease: false
259
264
  type: :runtime
265
+ - !ruby/object:Gem::Dependency
266
+ name: crimp
260
267
  version_requirements: !ruby/object:Gem::Requirement
261
268
  requirements:
262
269
  - - '>='
263
270
  - !ruby/object:Gem::Version
264
271
  version: '0'
265
- - !ruby/object:Gem::Dependency
266
272
  requirement: !ruby/object:Gem::Requirement
267
273
  requirements:
268
274
  - - '>='
269
275
  - !ruby/object:Gem::Version
270
276
  version: '0'
271
- name: crimp
272
277
  prerelease: false
273
278
  type: :runtime
274
- version_requirements: !ruby/object:Gem::Requirement
275
- requirements:
276
- - - '>='
277
- - !ruby/object:Gem::Version
278
- version: '0'
279
279
  description: Brokers requests for alephant components
280
280
  email:
281
281
  - stevenmajack@gmail.com