alephant-publisher-queue 2.5.0 → 2.6.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: bf29d6e5e6cd44bc99c3d654a013e57afb4191a2
4
- data.tar.gz: 019f8916b0859fb3e1eca573c08edff35ee8cd04
3
+ metadata.gz: 9d85acb1700dc11db1d701833055fc681c829de1
4
+ data.tar.gz: a409bff70bf7b7f3122d1eacf43dc0893c638ddc
5
5
  SHA512:
6
- metadata.gz: 11bcdfdb4998721749b617dcfb86196cf3d780666ee11f2d93f230270a0192653d71fd9e187a1bb99e9684b09c0d9926120e11466ec642a85b0d35fef208c757
7
- data.tar.gz: 37aa6ffdd3f8e356897d6f23184347c136ffd632211b75f35d1e8037d756582351df6e498bf4bbd72cddd6a4c287a462a73fee831f9a8750a5f405e03c784497
6
+ metadata.gz: 4ccf8e8b65b304ce50df32efa571ef3942d0bbd7675648aadb1d0c541665ebc7f4b2a135f4d3f2a1364404346b255d8ca66e25b231fbfe14909ea4c2cca53a7d
7
+ data.tar.gz: 24f6bc86e7397e5a0062a82357107d49ceef1dbb70a072015246399c4b9b901ed54e66e9a5a293e5a9b68108dcc9b699b242a26f02ea79a725d3a5afed6e235f
@@ -1 +1 @@
1
- jruby-1.7.17
1
+ 2.3
@@ -1,24 +1,10 @@
1
- sudo: false
2
- cache: bundler
3
1
  language: ruby
4
-
5
- # Ruby build matrix
6
2
  rvm:
7
- - 2.0
8
- - 2.1
9
- - 2.2
10
- - 2.3.0
11
- - 2.3.1
12
- - jruby
13
-
14
- # Environment variables
15
- env:
16
- - RUBYOPT="-W0"
17
-
18
- # Ensure we don't build for *every* commit (doesn't apply to PR builds)
19
- branches:
20
- only:
21
- - master
22
-
23
- script:
24
- - bundle exec rspec --format documentation
3
+ - "2.3"
4
+ - "jruby"
5
+ notifications:
6
+ email:
7
+ recipients:
8
+ - D&ENewsFrameworksTeam@bbc.co.uk
9
+ on_failure: change
10
+ on_success: never
@@ -30,14 +30,14 @@ Gem::Specification.new do |spec|
30
30
  spec.add_development_dependency "simplecov"
31
31
 
32
32
  spec.add_runtime_dependency "rake"
33
- spec.add_runtime_dependency "aws-sdk", "~> 1.0"
33
+ spec.add_runtime_dependency "aws-sdk-sqs"
34
34
  spec.add_runtime_dependency "crimp"
35
35
  spec.add_runtime_dependency "faraday"
36
36
  spec.add_runtime_dependency "dalli-elasticache"
37
37
  spec.add_runtime_dependency "alephant-support"
38
- spec.add_runtime_dependency "alephant-sequencer", "~> 3"
38
+ spec.add_runtime_dependency "alephant-sequencer"
39
39
  spec.add_runtime_dependency "alephant-storage"
40
- spec.add_runtime_dependency "alephant-logger", "~> 3.1"
41
- spec.add_runtime_dependency "alephant-lookup", "~> 2"
40
+ spec.add_runtime_dependency "alephant-logger"
41
+ spec.add_runtime_dependency "alephant-lookup"
42
42
  spec.add_runtime_dependency "alephant-renderer"
43
43
  end
@@ -1,12 +1,10 @@
1
- require "aws-sdk"
1
+ require "aws-sdk-sqs"
2
2
  require "yaml"
3
3
  require "alephant/logger"
4
4
 
5
5
  config_file = "config/aws.yaml"
6
6
 
7
- AWS.eager_autoload!
8
-
9
7
  if File.exist? config_file
10
8
  config = YAML.load(File.read(config_file))
11
- AWS.config(config)
9
+ Aws.config.update(config)
12
10
  end
@@ -1,4 +1,4 @@
1
- require "aws-sdk"
1
+ require "aws-sdk-sqs"
2
2
  require "alephant/logger"
3
3
 
4
4
  module Alephant
@@ -10,10 +10,12 @@ module Alephant
10
10
  @opts = opts
11
11
  end
12
12
 
13
- def consume(msg)
14
- return if msg.nil?
15
- write(msg)
16
- msg.delete
13
+ def consume(message_collection)
14
+ return unless message_collection && message_collection.size > 0
15
+
16
+ message = message_collection.first
17
+ write(message)
18
+ message.delete
17
19
  end
18
20
 
19
21
  private
@@ -54,34 +54,36 @@ module Alephant
54
54
  end
55
55
 
56
56
  def get_region
57
- opts.queue[:sqs_account_region] || AWS.config.region
57
+ # @TODO: Where does region come from?
58
+ opts.queue[:sqs_account_region] || Aws.config[:region] || 'eu-west-1'
58
59
  end
59
60
 
60
61
  def sqs_client
61
- @sqs_client ||= AWS::SQS.new(region: get_region)
62
+ @sqs_client ||= Aws::SQS::Client.new(sqs_queue_options)
62
63
  end
63
64
 
64
65
  def sqs_queue_options
65
- (opts.queue[:aws_account_id].nil? ? {} : fallback).tap do |ops|
66
- logger.info(
67
- "event" => "SQSQueueOptionsConfigured",
68
- "options" => ops,
69
- "method" => "#{self.class}#sqs_queue_options"
70
- )
71
- end
72
- end
66
+ options = {}
67
+ options[:endpoint] = ENV['AWS_SQS_ENDPOINT'] if ENV['AWS_SQS_ENDPOINT']
68
+ options[:region] = get_region
73
69
 
74
- def fallback
75
- {
76
- :queue_owner_aws_account_id => opts.queue[:aws_account_id]
77
- }
70
+ logger.info(
71
+ "event" => "SQSQueueOptionsConfigured",
72
+ "options" => options,
73
+ "method" => "#{self.class}#sqs_queue_options"
74
+ )
75
+
76
+ options
78
77
  end
79
78
 
80
79
  def aws_queue
81
- queue_url = sqs_client.queues.url_for(
82
- opts.queue[:sqs_queue_name], sqs_queue_options
83
- )
84
- sqs_client.queues[queue_url]
80
+ options = { queue_name: opts.queue[:sqs_queue_name] }
81
+ options[:queue_owner_aws_account_id] = opts.queue[:aws_account_id] if opts.queue[:aws_account_id]
82
+
83
+ queue_url = sqs_client.get_queue_url(options).queue_url
84
+
85
+ resource = Aws::SQS::Resource.new(client: sqs_client)
86
+ resource.queue(queue_url)
85
87
  end
86
88
  end
87
89
  end
@@ -1,10 +1,11 @@
1
1
  require 'faraday'
2
- require 'aws-sdk'
2
+ require "aws-sdk-sqs"
3
3
  require 'crimp'
4
4
  require 'alephant/publisher/queue/processor'
5
5
  require 'alephant/publisher/queue/revalidate_writer'
6
6
  require 'json'
7
7
  require 'alephant/logger'
8
+ require 'ostruct'
8
9
 
9
10
  module Alephant
10
11
  module Publisher
@@ -20,16 +21,19 @@ module Alephant
20
21
  @http_response_processor = http_response_processor
21
22
  end
22
23
 
23
- def consume(message)
24
- return if message.nil?
24
+ def consume(message_collection)
25
+ return unless message_collection && message_collection.size > 0
26
+
27
+ message = message_collection.first
25
28
 
26
29
  msg_body = message_content(message)
27
30
 
31
+ # @TODO: This is not a http response but a data struct. We should look at renaming this.
28
32
  http_response = {
29
33
  renderer_id: msg_body.fetch(:id),
30
34
  http_options: msg_body,
31
35
  http_response: get(message),
32
- ttl: http_response_processor.ttl(msg_body)
36
+ ttl: http_response_processor.ttl(msg_body).to_s # @TODO: What happens if this is nil? Storage requires this to be a string.
33
37
  }
34
38
 
35
39
  http_message = build_http_message(message, ::JSON.generate(http_response))
@@ -76,11 +80,9 @@ module Alephant
76
80
  end
77
81
 
78
82
  def build_http_message(message, http_response)
79
- # I feel dirty...
80
- # FIXME: refactor `Writer` so it's not so tightly coupled to a AWS::SQS::ReceivedMessage object
81
- http_message = message.dup
82
- http_message.instance_variable_set(:@body, http_response)
83
- http_message
83
+ OpenStruct.new({
84
+ body: http_response
85
+ })
84
86
  end
85
87
 
86
88
  def get(message)
@@ -72,11 +72,13 @@ module Alephant
72
72
  end
73
73
 
74
74
  def storage_opts
75
- { ttl: message_content[:ttl] }
75
+ { ttl: message_content[:ttl] } # @TODO: What happens if this is nil?
76
76
  end
77
77
 
78
78
  def config
79
- @config.merge(renderer_id: message_content.fetch(:renderer_id))
79
+ # @TODO: This part needs refactoring
80
+ @config[:renderer_id] = message_content.fetch(:renderer_id)
81
+ @config
80
82
  end
81
83
 
82
84
  def http_data
@@ -1,4 +1,4 @@
1
- require "aws-sdk"
1
+ require "aws-sdk-sqs"
2
2
  require "alephant/logger"
3
3
 
4
4
  module Alephant
@@ -27,7 +27,7 @@ module Alephant
27
27
  end
28
28
 
29
29
  def message
30
- receive.tap { |m| process(m) unless m.nil? }
30
+ receive.tap { |m| process(m) }
31
31
  end
32
32
 
33
33
  private
@@ -43,13 +43,16 @@ module Alephant
43
43
  end
44
44
 
45
45
  def process(m)
46
+ return unless m.size > 0
47
+
46
48
  logger.metric "MessagesReceived"
47
49
  logger.info(
48
50
  "event" => "QueueMessageReceived",
49
- "messageId" => m.id,
51
+ "messageId" => m.first.message_id,
50
52
  "method" => "#{self.class}#process"
51
53
  )
52
- archive m
54
+ # @TODO: Look at archiver as should support message from collection.
55
+ archive m.first
53
56
  end
54
57
 
55
58
  def archive(m)
@@ -66,9 +69,10 @@ module Alephant
66
69
  end
67
70
 
68
71
  def receive
69
- queue.receive_message(
70
- :visibility_timeout => timeout,
71
- :wait_time_seconds => wait_time
72
+ queue.receive_messages(
73
+ :visibility_timeout => timeout,
74
+ :wait_time_seconds => wait_time,
75
+ :max_number_of_messages => 1
72
76
  )
73
77
  end
74
78
  end
@@ -1,7 +1,7 @@
1
1
  module Alephant
2
2
  module Publisher
3
3
  module Queue
4
- VERSION = '2.5.0'.freeze
4
+ VERSION = '2.6.0'.freeze
5
5
  end
6
6
  end
7
7
  end
@@ -11,11 +11,12 @@ describe Alephant::Publisher::Queue::Processor do
11
11
  ).to receive(:run!)
12
12
  end
13
13
 
14
- describe "#consume(msg)" do
14
+ describe "#consume" do
15
15
  it "Consume the message and deletes it" do
16
- msg = instance_double(AWS::SQS::ReceivedMessage, :delete => nil)
17
- expect(msg).to receive(:delete)
18
- subject.consume(msg)
16
+ message = instance_double(Aws::SQS::Message, :delete => nil)
17
+ message_collection = [message]
18
+ expect(message).to receive(:delete)
19
+ subject.consume(message_collection)
19
20
  end
20
21
  end
21
22
  end
@@ -32,7 +32,8 @@ RSpec.describe Alephant::Publisher::Queue::RevalidateProcessor do
32
32
  let(:cache_double) { instance_double(Dalli::Client, delete: nil) }
33
33
  let(:elasticache_double) { instance_double(Dalli::ElastiCache, client: cache_double) }
34
34
 
35
- let(:message) { instance_double(AWS::SQS::ReceivedMessage, body: JSON.generate(message_body), delete: nil) }
35
+ let(:message) { instance_double(Aws::SQS::Message, body: JSON.generate(message_body), delete: nil) }
36
+ let(:message_collection) { [message] }
36
37
  let(:message_body) { { id: '', batch_id: '', options: {} } }
37
38
 
38
39
  before do
@@ -64,7 +65,7 @@ RSpec.describe Alephant::Publisher::Queue::RevalidateProcessor do
64
65
 
65
66
  expect(writer_double).to receive(:run!)
66
67
 
67
- subject.consume(message)
68
+ subject.consume(message_collection)
68
69
  end
69
70
 
70
71
  it 'passes the response to the http_response_processor' do
@@ -73,7 +74,7 @@ RSpec.describe Alephant::Publisher::Queue::RevalidateProcessor do
73
74
  .with(message_body, resp_status, resp_body)
74
75
  .and_call_original
75
76
 
76
- subject.consume(message)
77
+ subject.consume(message_collection)
77
78
  end
78
79
 
79
80
  it "calls the 'ttl' method on the http_response_processor" do
@@ -82,19 +83,19 @@ RSpec.describe Alephant::Publisher::Queue::RevalidateProcessor do
82
83
  .with(message_body)
83
84
  .and_call_original
84
85
 
85
- subject.consume(message)
86
+ subject.consume(message_collection)
86
87
  end
87
88
 
88
89
  it 'deletes the message from the queue' do
89
90
  expect(message).to receive(:delete)
90
91
 
91
- subject.consume(message)
92
+ subject.consume(message_collection)
92
93
  end
93
94
 
94
95
  it "removes the 'inflight' cache message" do
95
96
  expect(cache_double).to receive(:delete)
96
97
 
97
- subject.consume(message)
98
+ subject.consume(message_collection)
98
99
  end
99
100
  end
100
101
 
@@ -106,34 +107,34 @@ RSpec.describe Alephant::Publisher::Queue::RevalidateProcessor do
106
107
  it 'does not call #run! on the writer' do
107
108
  expect(writer_double).to_not receive(:run!)
108
109
 
109
- expect { subject.consume(message) }
110
+ expect { subject.consume(message_collection) }
110
111
  .to raise_error(Faraday::TimeoutError)
111
112
  end
112
113
 
113
114
  it 'does NOT delele the message from the queue' do
114
115
  expect(message).to_not receive(:delete)
115
116
 
116
- expect { subject.consume(message) }
117
+ expect { subject.consume(message_collection) }
117
118
  .to raise_error(Faraday::TimeoutError)
118
119
  end
119
120
 
120
121
  it "does not remove the 'inflight' cache message" do
121
122
  expect(cache_double).to_not receive(:delete)
122
123
 
123
- expect { subject.consume(message) }
124
+ expect { subject.consume(message_collection) }
124
125
  .to raise_error(Faraday::TimeoutError)
125
126
  end
126
127
  end
127
128
  end
128
129
 
129
130
  context 'when there is no message passed through' do
130
- let(:message) { nil }
131
+ let(:message_collection) { [] }
131
132
 
132
133
  it 'does nothing' do
133
134
  expect(writer_double).to_not receive(:run!)
134
135
  expect(cache_double).to_not receive(:delete)
135
136
 
136
- subject.consume(message)
137
+ subject.consume(message_collection)
137
138
  end
138
139
  end
139
140
  end
@@ -2,12 +2,12 @@ require "spec_helper"
2
2
 
3
3
  describe Alephant::Publisher::Queue::SQSHelper::Archiver do
4
4
  let(:storage) { instance_double(Alephant::Storage, :put => nil) }
5
- let(:queue) { instance_double(AWS::SQS::Queue, :url => nil) }
5
+ let(:queue) { instance_double(Aws::SQS::Queue, :url => nil) }
6
6
  let(:msg_body) { { :Message => JSON.generate(msg_uri) } }
7
7
  let(:msg_uri) { { :uri => "/content/asset/newsbeat" } }
8
8
  let(:message) do
9
9
  instance_double(
10
- "AWS::SQS::ReceivedMessage",
10
+ "Aws::SQS::ReceivedMessage",
11
11
  :id => "id",
12
12
  :md5 => "qux",
13
13
  :queue => queue,
@@ -6,7 +6,7 @@ describe Alephant::Publisher::Queue::SQSHelper::Queue do
6
6
  m = double("message").as_null_object
7
7
  q = double("queue").as_null_object
8
8
 
9
- expect(q).to receive(:receive_message).and_return(m)
9
+ expect(q).to receive(:receive_messages).and_return(m)
10
10
 
11
11
  instance = Alephant::Publisher::Queue::SQSHelper::Queue.new(q)
12
12
 
@@ -18,7 +18,7 @@ describe Alephant::Publisher::Queue::SQSHelper::Queue do
18
18
  m = double("message").as_null_object
19
19
  q = double("queue").as_null_object
20
20
 
21
- expect(q).to receive(:receive_message).and_return(m)
21
+ expect(q).to receive(:receive_messages).and_return(m)
22
22
  expect(a).to receive(:see).with(m)
23
23
 
24
24
  instance = Alephant::Publisher::Queue::SQSHelper::Queue.new(q, a)
@@ -15,8 +15,6 @@ describe Alephant::Publisher::Queue::Writer do
15
15
  end
16
16
 
17
17
  before(:each) do
18
- AWS.stub!
19
-
20
18
  allow_any_instance_of(Alephant::Storage).to receive(:initialize)
21
19
  .with(
22
20
  opts[:s3_bucket_id],
@@ -1,19 +1,20 @@
1
1
  require "spec_helper"
2
2
 
3
3
  describe Alephant::Publisher::Queue do
4
- let(:options) { Alephant::Publisher::Queue::Options.new }
5
- let(:queue) { double(AWS::SQS::Queue, :url => nil) }
6
- let(:client_double) { double(AWS::SQS, :queues => queue_double) }
7
- let(:queue_double) do
8
- double("AWS::SQS::QueueCollection", :[] => queue, :url_for => nil)
9
- end
4
+ let(:options) { Alephant::Publisher::Queue::Options.new }
5
+ let(:fake_client) { Aws::SQS::Client.new(stub_responses: true) }
10
6
 
11
7
  before(:each) do
12
- expect(AWS::SQS).to receive(:new).and_return(client_double)
8
+ allow_any_instance_of(Alephant::Publisher::Queue::Publisher).to receive(:sqs_client).and_return(fake_client)
9
+ fake_client.stub_responses(:get_queue_url, { queue_url: 'http://sqs.aws.myqueue/id' })
13
10
  end
14
11
 
15
12
  describe ".create" do
16
13
  it "sets parser, sequencer, queue and writer" do
14
+ options.add_queue(
15
+ :sqs_queue_name => "bar",
16
+ :aws_account_id => "foo"
17
+ )
17
18
  instance = Alephant::Publisher::Queue.create(options)
18
19
  expect(instance.queue)
19
20
  .to be_a Alephant::Publisher::Queue::SQSHelper::Queue
@@ -27,12 +28,9 @@ describe Alephant::Publisher::Queue do
27
28
  :aws_account_id => "foo"
28
29
  )
29
30
 
30
- expect(queue_double).to receive(:url_for).with(
31
- "bar",
32
- :queue_owner_aws_account_id => "foo"
33
- )
31
+ publisher = Alephant::Publisher::Queue.create(options)
34
32
 
35
- Alephant::Publisher::Queue.create(options)
33
+ expect(publisher.queue.queue).to be_a(Aws::SQS::Queue)
36
34
  end
37
35
  end
38
36
 
@@ -41,9 +39,9 @@ describe Alephant::Publisher::Queue do
41
39
  options = Alephant::Publisher::Queue::Options.new
42
40
  options.add_queue(:sqs_queue_name => "bar")
43
41
 
44
- expect(queue_double).to receive(:url_for).with("bar", {})
42
+ publisher = Alephant::Publisher::Queue.create(options)
45
43
 
46
- Alephant::Publisher::Queue.create(options)
44
+ expect(publisher.queue.queue).to be_a(Aws::SQS::Queue)
47
45
  end
48
46
  end
49
47
  end
@@ -1,9 +1,11 @@
1
1
  $LOAD_PATH << File.join(File.dirname(__FILE__), "..", "lib")
2
2
 
3
3
  require "pry"
4
- require "aws-sdk"
4
+ require "aws-sdk-sqs"
5
5
  require "simplecov"
6
6
 
7
+ ENV['AWS_REGION'] = 'eu-west-1'
8
+
7
9
  SimpleCov.start do
8
10
  add_filter "/spec/"
9
11
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: alephant-publisher-queue
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.5.0
4
+ version: 2.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - BBC News
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-04-24 00:00:00.000000000 Z
11
+ date: 2018-05-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -179,19 +179,19 @@ dependencies:
179
179
  - !ruby/object:Gem::Version
180
180
  version: '0'
181
181
  - !ruby/object:Gem::Dependency
182
- name: aws-sdk
182
+ name: aws-sdk-sqs
183
183
  requirement: !ruby/object:Gem::Requirement
184
184
  requirements:
185
- - - "~>"
185
+ - - ">="
186
186
  - !ruby/object:Gem::Version
187
- version: '1.0'
187
+ version: '0'
188
188
  type: :runtime
189
189
  prerelease: false
190
190
  version_requirements: !ruby/object:Gem::Requirement
191
191
  requirements:
192
- - - "~>"
192
+ - - ">="
193
193
  - !ruby/object:Gem::Version
194
- version: '1.0'
194
+ version: '0'
195
195
  - !ruby/object:Gem::Dependency
196
196
  name: crimp
197
197
  requirement: !ruby/object:Gem::Requirement
@@ -252,16 +252,16 @@ dependencies:
252
252
  name: alephant-sequencer
253
253
  requirement: !ruby/object:Gem::Requirement
254
254
  requirements:
255
- - - "~>"
255
+ - - ">="
256
256
  - !ruby/object:Gem::Version
257
- version: '3'
257
+ version: '0'
258
258
  type: :runtime
259
259
  prerelease: false
260
260
  version_requirements: !ruby/object:Gem::Requirement
261
261
  requirements:
262
- - - "~>"
262
+ - - ">="
263
263
  - !ruby/object:Gem::Version
264
- version: '3'
264
+ version: '0'
265
265
  - !ruby/object:Gem::Dependency
266
266
  name: alephant-storage
267
267
  requirement: !ruby/object:Gem::Requirement
@@ -280,30 +280,30 @@ dependencies:
280
280
  name: alephant-logger
281
281
  requirement: !ruby/object:Gem::Requirement
282
282
  requirements:
283
- - - "~>"
283
+ - - ">="
284
284
  - !ruby/object:Gem::Version
285
- version: '3.1'
285
+ version: '0'
286
286
  type: :runtime
287
287
  prerelease: false
288
288
  version_requirements: !ruby/object:Gem::Requirement
289
289
  requirements:
290
- - - "~>"
290
+ - - ">="
291
291
  - !ruby/object:Gem::Version
292
- version: '3.1'
292
+ version: '0'
293
293
  - !ruby/object:Gem::Dependency
294
294
  name: alephant-lookup
295
295
  requirement: !ruby/object:Gem::Requirement
296
296
  requirements:
297
- - - "~>"
297
+ - - ">="
298
298
  - !ruby/object:Gem::Version
299
- version: '2'
299
+ version: '0'
300
300
  type: :runtime
301
301
  prerelease: false
302
302
  version_requirements: !ruby/object:Gem::Requirement
303
303
  requirements:
304
- - - "~>"
304
+ - - ">="
305
305
  - !ruby/object:Gem::Version
306
- version: '2'
306
+ version: '0'
307
307
  - !ruby/object:Gem::Dependency
308
308
  name: alephant-renderer
309
309
  requirement: !ruby/object:Gem::Requirement