pheme 3.3.2 → 4.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.circleci/config.yml +15 -11
- data/.rubocop_todo.yml +24 -17
- data/CHANGELOG.md +17 -0
- data/catalog-info.yaml +12 -0
- data/lib/pheme/configuration.rb +1 -2
- data/lib/pheme/message_handler.rb +3 -2
- data/lib/pheme/queue_poller.rb +38 -7
- data/lib/pheme/topic_publisher.rb +3 -2
- data/lib/pheme/version.rb +1 -1
- data/pheme.gemspec +1 -1
- data/sonar-project.properties +4 -0
- data/spec/queue_poller_spec.rb +93 -12
- data/spec/spec_helper.rb +1 -1
- data/spec/support/example_queue_poller.rb +2 -2
- data/spec/support/example_queue_poller_with_inlined_handler.rb +2 -1
- data/spec/topic_publisher_spec.rb +5 -0
- metadata +8 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 38d24eb669b4e507e93aca15a084c375d9dd5d9d6a734d6e7c0ca3336d216f2e
|
4
|
+
data.tar.gz: f3e87e1c473b1f8ec4b7adfc4c94891026f29ad4fc4d192d982d207233993601
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ccdd560c4cb055cd877804f57b73bbab6a2d95d7a8e4140d3b38e4d6e6c9d5cee6dbd8d632a9c8d4e6651d295317d55ffdb3e4cbbd689f65344f6dcf21d2fbd4
|
7
|
+
data.tar.gz: 4069eea7b5d377d3e245d4e4596abd18d7fe9534112967eadb1597eb225f048f97d9324b1de1a20683c9f1991ef508ae06786d63893cbdf78796d8091f01468b
|
data/.circleci/config.yml
CHANGED
@@ -2,17 +2,17 @@ version: 2
|
|
2
2
|
|
3
3
|
references:
|
4
4
|
defaults:
|
5
|
-
|
5
|
+
2_4_10: &defaults_2_4_10
|
6
6
|
working_directory: ~/wealthsimple
|
7
7
|
docker:
|
8
|
-
- image: circleci/ruby:2.4.
|
8
|
+
- image: circleci/ruby:2.4.10
|
9
9
|
environment:
|
10
10
|
RAILS_ENV: test
|
11
11
|
|
12
|
-
|
12
|
+
2_5_8: &defaults
|
13
13
|
working_directory: ~/wealthsimple
|
14
14
|
docker:
|
15
|
-
- image: circleci/ruby:2.5.
|
15
|
+
- image: circleci/ruby:2.5.8
|
16
16
|
environment:
|
17
17
|
RAILS_ENV: test
|
18
18
|
|
@@ -46,8 +46,8 @@ references:
|
|
46
46
|
--format documentation
|
47
47
|
|
48
48
|
jobs:
|
49
|
-
|
50
|
-
<<: *
|
49
|
+
checkout_and_bundle_2_4_10:
|
50
|
+
<<: *defaults_2_4_10
|
51
51
|
environment:
|
52
52
|
COVERALLS_REPO_TOKEN: ''
|
53
53
|
steps:
|
@@ -109,17 +109,20 @@ workflows:
|
|
109
109
|
version: 2
|
110
110
|
build:
|
111
111
|
jobs:
|
112
|
-
-
|
112
|
+
- checkout_and_bundle_2_4_10:
|
113
113
|
context: wealthsimple
|
114
114
|
- checkout_and_bundle:
|
115
115
|
context: wealthsimple
|
116
116
|
- rspec:
|
117
|
+
context: wealthsimple
|
117
118
|
requires:
|
118
119
|
- checkout_and_bundle
|
119
120
|
- lint_check:
|
121
|
+
context: wealthsimple
|
120
122
|
requires:
|
121
123
|
- checkout_and_bundle
|
122
124
|
- vulnerability_check:
|
125
|
+
context: wealthsimple
|
123
126
|
requires:
|
124
127
|
- checkout_and_bundle
|
125
128
|
- release:
|
@@ -128,10 +131,10 @@ workflows:
|
|
128
131
|
branches:
|
129
132
|
only: master
|
130
133
|
requires:
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
134
|
+
- checkout_and_bundle_2_4_10
|
135
|
+
- rspec
|
136
|
+
- lint_check
|
137
|
+
- vulnerability_check
|
135
138
|
|
136
139
|
security-audit:
|
137
140
|
triggers:
|
@@ -145,5 +148,6 @@ workflows:
|
|
145
148
|
- checkout_and_bundle:
|
146
149
|
context: wealthsimple
|
147
150
|
- vulnerability_check:
|
151
|
+
context: wealthsimple
|
148
152
|
requires:
|
149
153
|
- checkout_and_bundle
|
data/.rubocop_todo.yml
CHANGED
@@ -1,42 +1,42 @@
|
|
1
1
|
# This configuration was generated by
|
2
2
|
# `rubocop --auto-gen-config`
|
3
|
-
# on
|
3
|
+
# on 2021-01-07 16:23:09 UTC using RuboCop version 1.6.1.
|
4
4
|
# The point is for the user to remove these configuration records
|
5
5
|
# one by one as the offenses are removed from the code base.
|
6
6
|
# Note that changes in the inspected code, or installation of new
|
7
7
|
# versions of RuboCop, may require this file to be generated again.
|
8
8
|
|
9
|
+
# Offense count: 19
|
10
|
+
# Cop supports --auto-correct.
|
11
|
+
# Configuration parameters: AutoCorrect, AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns.
|
12
|
+
# URISchemes: http, https
|
13
|
+
Layout/LineLength:
|
14
|
+
Max: 147
|
15
|
+
|
9
16
|
# Offense count: 2
|
17
|
+
# Configuration parameters: IgnoredMethods, CountRepeatedAttributes.
|
10
18
|
Metrics/AbcSize:
|
11
19
|
Max: 22
|
12
20
|
|
13
21
|
# Offense count: 1
|
14
|
-
# Configuration parameters:
|
15
|
-
Metrics/ClassLength:
|
16
|
-
Max: 164
|
17
|
-
|
18
|
-
# Offense count: 1
|
22
|
+
# Configuration parameters: IgnoredMethods.
|
19
23
|
Metrics/CyclomaticComplexity:
|
20
24
|
Max: 10
|
21
25
|
|
22
|
-
# Offense count: 17
|
23
|
-
# Cop supports --auto-correct.
|
24
|
-
# Configuration parameters: AutoCorrect, AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns.
|
25
|
-
# URISchemes: http, https
|
26
|
-
Metrics/LineLength:
|
27
|
-
Max: 147
|
28
|
-
|
29
26
|
# Offense count: 3
|
30
|
-
# Configuration parameters: CountComments, ExcludedMethods.
|
27
|
+
# Configuration parameters: CountComments, CountAsOne, ExcludedMethods, IgnoredMethods.
|
28
|
+
# IgnoredMethods: extended, extended, extended, extended, extended, extended, extended, extended, extended, extended, extended, extended, extended, extended, extended, extended, extended, extended, extended, extended, extended, extended, extended, extended, extended, extended, extended, extended, extended, extended, extended, extended, extended, extended, extended, extended, extended, extended, extended, extended, extended, extended, extended, extended, extended, extended, extended
|
31
29
|
Metrics/MethodLength:
|
32
30
|
Max: 28
|
33
31
|
|
34
32
|
# Offense count: 1
|
33
|
+
# Configuration parameters: IgnoredMethods.
|
35
34
|
Metrics/PerceivedComplexity:
|
36
35
|
Max: 11
|
37
36
|
|
38
|
-
# Offense count:
|
39
|
-
# Configuration parameters: CustomTransform, IgnoreMethods.
|
37
|
+
# Offense count: 9
|
38
|
+
# Configuration parameters: Include, CustomTransform, IgnoreMethods, SpecSuffixOnly.
|
39
|
+
# Include: **/*_spec*rb*, **/spec/**/*
|
40
40
|
RSpec/FilePath:
|
41
41
|
Exclude:
|
42
42
|
- 'spec/configuration_spec.rb'
|
@@ -45,8 +45,8 @@ RSpec/FilePath:
|
|
45
45
|
- 'spec/message_type/aws_event_spec.rb'
|
46
46
|
- 'spec/message_type/sns_message_spec.rb'
|
47
47
|
- 'spec/queue_poller_spec.rb'
|
48
|
-
- 'spec/topic_publisher_spec.rb'
|
49
48
|
- 'spec/rollbar_spec.rb'
|
49
|
+
- 'spec/topic_publisher_spec.rb'
|
50
50
|
- 'spec/version_spec.rb'
|
51
51
|
|
52
52
|
# Offense count: 14
|
@@ -70,3 +70,10 @@ RSpec/VerifiedDoubles:
|
|
70
70
|
Style/GuardClause:
|
71
71
|
Exclude:
|
72
72
|
- 'lib/pheme/queue_poller.rb'
|
73
|
+
|
74
|
+
# Offense count: 2
|
75
|
+
# Cop supports --auto-correct.
|
76
|
+
Style/IfUnlessModifier:
|
77
|
+
Exclude:
|
78
|
+
- 'lib/pheme/queue_poller.rb'
|
79
|
+
- 'pheme.gemspec'
|
data/CHANGELOG.md
CHANGED
@@ -4,6 +4,23 @@ All notable changes to this project will be documented in this file.
|
|
4
4
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
5
5
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
6
6
|
|
7
|
+
## 4.0.2 - 2020-12-17
|
8
|
+
- Bump local dev version, rubocop fixes, add backstage catalog file + sonarqube project settings
|
9
|
+
|
10
|
+
## 4.0.1 - 2020-03-23
|
11
|
+
### Fixes
|
12
|
+
- Fixes 4.0.0. Instead of expecting message attributes in the message from `poll`, retrieves them from the right place.
|
13
|
+
|
14
|
+
## 4.0.0 - 2020-03-18
|
15
|
+
### Breaking Changes
|
16
|
+
- Add the ability for SQS to receive message attributes
|
17
|
+
- `handle` function of `QueuePoller` now takes a third parameter `message_attributes`
|
18
|
+
- blocks or `MessageHandler`s passed to `QueuePoller` can use this `message_attributes`
|
19
|
+
|
20
|
+
## 3.4.0 - 2020-03-17
|
21
|
+
### Added
|
22
|
+
- Add the ability to pass message attributes to SNS
|
23
|
+
|
7
24
|
## 3.3.0 - 2019-07-09
|
8
25
|
### Added
|
9
26
|
- Add more friendly options for initializing queue pollers by either:
|
data/catalog-info.yaml
ADDED
data/lib/pheme/configuration.rb
CHANGED
@@ -19,8 +19,7 @@ module Pheme
|
|
19
19
|
ATTRIBUTES = %i[sns_client sqs_client logger].freeze
|
20
20
|
OPTIONAL_ATTRIBUTES = %i[rollbar].freeze
|
21
21
|
|
22
|
-
attr_accessor(*ATTRIBUTES)
|
23
|
-
attr_accessor(*OPTIONAL_ATTRIBUTES)
|
22
|
+
attr_accessor(*ATTRIBUTES, *OPTIONAL_ATTRIBUTES)
|
24
23
|
|
25
24
|
def initialize
|
26
25
|
@logger ||= Logger.new(STDOUT) # rubocop:disable Lint/DisjunctiveAssignmentInConstructor
|
@@ -1,10 +1,11 @@
|
|
1
1
|
module Pheme
|
2
2
|
class MessageHandler
|
3
|
-
attr_reader :message, :metadata, :timestamp
|
3
|
+
attr_reader :message, :metadata, :message_attributes, :timestamp
|
4
4
|
|
5
|
-
def initialize(message:, metadata: {})
|
5
|
+
def initialize(message:, metadata: {}, message_attributes: {})
|
6
6
|
@message = message
|
7
7
|
@metadata = metadata
|
8
|
+
@message_attributes = message_attributes
|
8
9
|
end
|
9
10
|
|
10
11
|
def handle
|
data/lib/pheme/queue_poller.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
require_relative 'compression'
|
2
2
|
|
3
3
|
module Pheme
|
4
|
+
# rubocop:disable Metrics/ClassLength
|
4
5
|
class QueuePoller
|
5
6
|
include Compression
|
6
7
|
|
@@ -51,6 +52,7 @@ module Pheme
|
|
51
52
|
end
|
52
53
|
end
|
53
54
|
|
55
|
+
# rubocop:disable Metrics/AbcSize
|
54
56
|
def poll
|
55
57
|
time_start = log_polling_start
|
56
58
|
queue_poller.poll(poller_configuration) do |queue_message|
|
@@ -59,7 +61,8 @@ module Pheme
|
|
59
61
|
begin
|
60
62
|
content = parse_body(queue_message)
|
61
63
|
metadata = parse_metadata(queue_message)
|
62
|
-
|
64
|
+
message_attributes = parse_message_attributes(queue_message)
|
65
|
+
with_optional_connection_pool_block { handle(content, metadata, message_attributes) }
|
63
66
|
queue_poller.delete_message(queue_message)
|
64
67
|
log_delete(queue_message)
|
65
68
|
@messages_processed += 1
|
@@ -73,6 +76,7 @@ module Pheme
|
|
73
76
|
end
|
74
77
|
log_polling_end(time_start)
|
75
78
|
end
|
79
|
+
# rubocop:enable Metrics/AbcSize
|
76
80
|
|
77
81
|
# returns queue_message.body as hash,
|
78
82
|
# stores and parses get_content to body[:content]
|
@@ -102,7 +106,17 @@ module Pheme
|
|
102
106
|
|
103
107
|
def parse_metadata(queue_message)
|
104
108
|
message_body = JSON.parse(queue_message.body)
|
105
|
-
{ timestamp: message_body['Timestamp'] }
|
109
|
+
{ timestamp: message_body['Timestamp'], topic_arn: message_body['TopicArn'] }
|
110
|
+
end
|
111
|
+
|
112
|
+
def parse_message_attributes(queue_message)
|
113
|
+
message_body = JSON.parse(queue_message.body)
|
114
|
+
message_attributes = {}
|
115
|
+
message_body['MessageAttributes']&.each do |key, value|
|
116
|
+
message_attributes[key.to_sym] = coerce_message_attribute(value)
|
117
|
+
end
|
118
|
+
|
119
|
+
message_attributes
|
106
120
|
end
|
107
121
|
|
108
122
|
def get_metadata(message_body)
|
@@ -123,11 +137,11 @@ module Pheme
|
|
123
137
|
RecursiveOpenStruct.new({ wrapper: parsed_body }, recurse_over_arrays: true).wrapper
|
124
138
|
end
|
125
139
|
|
126
|
-
def handle(message, metadata)
|
140
|
+
def handle(message, metadata, message_attributes)
|
127
141
|
if @message_handler
|
128
|
-
@message_handler.new(message: message, metadata: metadata).handle
|
142
|
+
@message_handler.new(message: message, metadata: metadata, message_attributes: message_attributes).handle
|
129
143
|
elsif @block_message_handler
|
130
|
-
@block_message_handler.call(message, metadata)
|
144
|
+
@block_message_handler.call(message, metadata, message_attributes)
|
131
145
|
else
|
132
146
|
raise NotImplementedError
|
133
147
|
end
|
@@ -135,9 +149,25 @@ module Pheme
|
|
135
149
|
|
136
150
|
private
|
137
151
|
|
138
|
-
def
|
152
|
+
def coerce_message_attribute(value)
|
153
|
+
case value['Type']
|
154
|
+
when 'String'
|
155
|
+
value['Value']
|
156
|
+
when 'Number'
|
157
|
+
JSON.parse(value['Value'])
|
158
|
+
when 'String.Array'
|
159
|
+
JSON.parse(value['Value'])
|
160
|
+
when 'Binary'
|
161
|
+
value['Value']
|
162
|
+
else
|
163
|
+
Pheme.logger.info("Unsupported custom data type")
|
164
|
+
value["Value"]
|
165
|
+
end
|
166
|
+
end
|
167
|
+
|
168
|
+
def with_optional_connection_pool_block(&block)
|
139
169
|
if connection_pool_block
|
140
|
-
ActiveRecord::Base.connection_pool.with_connection
|
170
|
+
ActiveRecord::Base.connection_pool.with_connection(&block)
|
141
171
|
else
|
142
172
|
yield
|
143
173
|
end
|
@@ -192,4 +222,5 @@ module Pheme
|
|
192
222
|
}.to_json)
|
193
223
|
end
|
194
224
|
end
|
225
|
+
# rubocop:enable Metrics/ClassLength
|
195
226
|
end
|
@@ -34,7 +34,7 @@ module Pheme
|
|
34
34
|
raise NotImplementedError
|
35
35
|
end
|
36
36
|
|
37
|
-
def publish(message, sns_client: Pheme.configuration.sns_client)
|
37
|
+
def publish(message, sns_client: Pheme.configuration.sns_client, message_attributes: nil)
|
38
38
|
payload = {
|
39
39
|
message: "#{self.class} publishing message to #{topic_arn}",
|
40
40
|
body: message,
|
@@ -42,7 +42,8 @@ module Pheme
|
|
42
42
|
topic_arn: topic_arn,
|
43
43
|
}
|
44
44
|
Pheme.logger.info(payload.to_json)
|
45
|
-
|
45
|
+
|
46
|
+
sns_client.publish(topic_arn: topic_arn, message: serialize(message), message_attributes: message_attributes)
|
46
47
|
end
|
47
48
|
|
48
49
|
def serialize(message)
|
data/lib/pheme/version.rb
CHANGED
data/pheme.gemspec
CHANGED
@@ -29,7 +29,7 @@ Gem::Specification.new do |s|
|
|
29
29
|
s.add_dependency "smarter_csv", "~> 1"
|
30
30
|
|
31
31
|
s.add_development_dependency 'bundler'
|
32
|
-
s.add_development_dependency 'coveralls'
|
32
|
+
s.add_development_dependency 'coveralls', "~> 0.8"
|
33
33
|
s.add_development_dependency 'git'
|
34
34
|
s.add_development_dependency 'rake'
|
35
35
|
s.add_development_dependency 'rspec'
|
data/spec/queue_poller_spec.rb
CHANGED
@@ -2,6 +2,7 @@ describe Pheme::QueuePoller do
|
|
2
2
|
let(:valid_queue_poller) { ExampleQueuePoller.new(queue_url: queue_url) }
|
3
3
|
let(:queue_url) { "https://sqs.us-east-1.amazonaws.com/whatever" }
|
4
4
|
let(:timestamp) { '2018-04-17T21:45:05.915Z' }
|
5
|
+
let(:topic_arn) { 'arn:topic:test' }
|
5
6
|
|
6
7
|
let!(:queue_message) do
|
7
8
|
OpenStruct.new(
|
@@ -13,7 +14,7 @@ describe Pheme::QueuePoller do
|
|
13
14
|
let(:message_id) { SecureRandom.uuid }
|
14
15
|
|
15
16
|
context 'base poller' do
|
16
|
-
subject { described_class.new(queue_url: queue_url).handle(nil, nil) }
|
17
|
+
subject { described_class.new(queue_url: queue_url).handle(nil, nil, nil) }
|
17
18
|
|
18
19
|
it 'does not implement handle' do
|
19
20
|
expect { subject }.to raise_error(NotImplementedError)
|
@@ -89,13 +90,13 @@ describe Pheme::QueuePoller do
|
|
89
90
|
context 'when handling messages' do
|
90
91
|
context 'when doing it the old way, via the handle function' do
|
91
92
|
it 'uses the handle function by default' do
|
92
|
-
expect { described_class.new(queue_url: queue_url).handle(nil, nil) }.to raise_error(NotImplementedError)
|
93
|
+
expect { described_class.new(queue_url: queue_url).handle(nil, nil, nil) }.to raise_error(NotImplementedError)
|
93
94
|
end
|
94
95
|
end
|
95
96
|
|
96
97
|
context 'when given a message_handler as parameter' do
|
97
98
|
it 'uses default when given nil' do
|
98
|
-
expect { described_class.new(queue_url: queue_url, message_handler: nil).handle(nil, nil) }.to raise_error(NotImplementedError)
|
99
|
+
expect { described_class.new(queue_url: queue_url, message_handler: nil).handle(nil, nil, nil) }.to raise_error(NotImplementedError)
|
99
100
|
end
|
100
101
|
|
101
102
|
it 'uses default when given invalid message_handler' do
|
@@ -105,9 +106,11 @@ describe Pheme::QueuePoller do
|
|
105
106
|
it 'uses handler when given one' do
|
106
107
|
mock_handler = double('MessageHandler')
|
107
108
|
allow(mock_handler).to receive(:handle)
|
108
|
-
allow(ExampleMessageHandler).to receive(:new).
|
109
|
+
allow(ExampleMessageHandler).to receive(:new).
|
110
|
+
with(message: 'message', metadata: 'metadata', message_attributes: 'message_attributes').
|
111
|
+
and_return(mock_handler)
|
109
112
|
|
110
|
-
described_class.new(queue_url: queue_url, message_handler: ExampleMessageHandler).handle('message', 'metadata')
|
113
|
+
described_class.new(queue_url: queue_url, message_handler: ExampleMessageHandler).handle('message', 'metadata', 'message_attributes')
|
111
114
|
expect(mock_handler).to have_received(:handle).once
|
112
115
|
end
|
113
116
|
end
|
@@ -116,12 +119,12 @@ describe Pheme::QueuePoller do
|
|
116
119
|
it 'uses handler when given one' do
|
117
120
|
mock_handler = spy('MessageHandler')
|
118
121
|
|
119
|
-
poller = described_class.new(queue_url: queue_url) do |message, metadata|
|
120
|
-
mock_handler.process(message, metadata)
|
122
|
+
poller = described_class.new(queue_url: queue_url) do |message, metadata, message_attributes|
|
123
|
+
mock_handler.process(message, metadata, message_attributes)
|
121
124
|
end
|
122
|
-
poller.handle('message', 'metadata')
|
125
|
+
poller.handle('message', 'metadata', 'message_attributes')
|
123
126
|
|
124
|
-
expect(mock_handler).to have_received(:process).with('message', 'metadata').once
|
127
|
+
expect(mock_handler).to have_received(:process).with('message', 'metadata', 'message_attributes').once
|
125
128
|
end
|
126
129
|
|
127
130
|
it 'fails on invalid handler' do
|
@@ -133,6 +136,62 @@ describe Pheme::QueuePoller do
|
|
133
136
|
end
|
134
137
|
end
|
135
138
|
|
139
|
+
describe '#parse_message_attributes' do
|
140
|
+
subject { described_class.new(queue_url: queue_url).parse_message_attributes(queue_message) }
|
141
|
+
|
142
|
+
context 'when no message_attributes' do
|
143
|
+
it { is_expected.to eq({}) }
|
144
|
+
end
|
145
|
+
|
146
|
+
context 'when message attributes' do
|
147
|
+
let(:queue_message) do
|
148
|
+
OpenStruct.new(
|
149
|
+
body: {
|
150
|
+
Message: message,
|
151
|
+
MessageAttributes: {
|
152
|
+
key: { Type: data_type, Value: string_value },
|
153
|
+
},
|
154
|
+
}.to_json,
|
155
|
+
message_id: message_id,
|
156
|
+
)
|
157
|
+
end
|
158
|
+
|
159
|
+
context 'when data_type is String' do
|
160
|
+
let(:data_type) { 'String' }
|
161
|
+
let(:string_value) { 'some-string-value' }
|
162
|
+
let(:expected_value) { 'some-string-value' }
|
163
|
+
|
164
|
+
its([:key]) { is_expected.to eq(expected_value) }
|
165
|
+
end
|
166
|
+
|
167
|
+
context 'when data_type is Number' do
|
168
|
+
let(:data_type) { 'Number' }
|
169
|
+
|
170
|
+
context 'and it is an int' do
|
171
|
+
let(:string_value) { '1' }
|
172
|
+
let(:expected_value) { 1 }
|
173
|
+
|
174
|
+
its([:key]) { is_expected.to eq(expected_value) }
|
175
|
+
end
|
176
|
+
|
177
|
+
context 'and it is a float' do
|
178
|
+
let(:string_value) { '1.5' }
|
179
|
+
let(:expected_value) { 1.5 }
|
180
|
+
|
181
|
+
its([:key]) { is_expected.to eq(expected_value) }
|
182
|
+
end
|
183
|
+
end
|
184
|
+
|
185
|
+
context 'when data_type is String.array' do
|
186
|
+
let(:data_type) { 'String.Array' }
|
187
|
+
let(:string_value) { '["sdfsdf",1,2,null,true,false]' }
|
188
|
+
let(:expected_value) { ["sdfsdf", 1, 2, nil, true, false] }
|
189
|
+
|
190
|
+
its([:key]) { is_expected.to eq(expected_value) }
|
191
|
+
end
|
192
|
+
end
|
193
|
+
end
|
194
|
+
|
136
195
|
describe "#parse_body" do
|
137
196
|
subject { poller.parse_body(queue_message) }
|
138
197
|
|
@@ -182,6 +241,7 @@ describe Pheme::QueuePoller do
|
|
182
241
|
it { is_expected.to be_a(Array) }
|
183
242
|
its(:first) { is_expected.to be_a(Array) }
|
184
243
|
its('first.first') { is_expected.to be_a(RecursiveOpenStruct) }
|
244
|
+
|
185
245
|
it "parses the nested object" do
|
186
246
|
expect(subject.first.first.test).to eq('test')
|
187
247
|
end
|
@@ -214,7 +274,15 @@ describe Pheme::QueuePoller do
|
|
214
274
|
let(:mock_connection_pool) { double }
|
215
275
|
|
216
276
|
let(:message) { { status: 'complete' } }
|
217
|
-
let(:notification) {
|
277
|
+
let(:notification) {
|
278
|
+
{
|
279
|
+
'MessageId' => SecureRandom.uuid,
|
280
|
+
'Message' => message.to_json,
|
281
|
+
'Type' => 'Notification',
|
282
|
+
'Timestamp' => timestamp,
|
283
|
+
'TopicArn' => topic_arn,
|
284
|
+
}
|
285
|
+
}
|
218
286
|
let!(:queue_message) do
|
219
287
|
OpenStruct.new(
|
220
288
|
body: notification.to_json,
|
@@ -239,7 +307,15 @@ describe Pheme::QueuePoller do
|
|
239
307
|
subject { ExampleQueuePoller.new(queue_url: queue_url) }
|
240
308
|
|
241
309
|
let(:message) { { status: 'complete' } }
|
242
|
-
let(:notification) {
|
310
|
+
let(:notification) {
|
311
|
+
{
|
312
|
+
'MessageId' => SecureRandom.uuid,
|
313
|
+
'Message' => message.to_json,
|
314
|
+
'Type' => 'Notification',
|
315
|
+
'Timestamp' => timestamp,
|
316
|
+
'TopicArn' => topic_arn,
|
317
|
+
}
|
318
|
+
}
|
243
319
|
let!(:queue_message) do
|
244
320
|
OpenStruct.new(
|
245
321
|
body: notification.to_json,
|
@@ -268,6 +344,7 @@ describe Pheme::QueuePoller do
|
|
268
344
|
'Message' => message.to_json,
|
269
345
|
'Type' => 'Notification',
|
270
346
|
'Timestamp' => timestamp,
|
347
|
+
'TopicArn' => topic_arn,
|
271
348
|
}
|
272
349
|
end
|
273
350
|
let!(:queue_message) do
|
@@ -283,7 +360,11 @@ describe Pheme::QueuePoller do
|
|
283
360
|
end
|
284
361
|
|
285
362
|
it "handles the message" do
|
286
|
-
expect(ExampleMessageHandler).to receive(:new).with(
|
363
|
+
expect(ExampleMessageHandler).to receive(:new).with(
|
364
|
+
message: RecursiveOpenStruct.new(message),
|
365
|
+
metadata: { timestamp: timestamp, topic_arn: topic_arn },
|
366
|
+
message_attributes: {},
|
367
|
+
)
|
287
368
|
subject.poll
|
288
369
|
end
|
289
370
|
|
data/spec/spec_helper.rb
CHANGED
@@ -3,10 +3,10 @@ class ExampleQueuePoller < Pheme::QueuePoller
|
|
3
3
|
super(queue_url: queue_url, **kwargs)
|
4
4
|
end
|
5
5
|
|
6
|
-
def handle(message, metadata)
|
6
|
+
def handle(message, metadata, message_attributes)
|
7
7
|
case message.status
|
8
8
|
when 'complete', 'rejected'
|
9
|
-
ExampleMessageHandler.new(message: message, metadata: metadata).handle
|
9
|
+
ExampleMessageHandler.new(message: message, metadata: metadata, message_attributes: message_attributes).handle
|
10
10
|
else
|
11
11
|
raise ArgumentError, "Unknown message status: #{message.status}"
|
12
12
|
end
|
@@ -36,10 +36,12 @@ describe Pheme::TopicPublisher do
|
|
36
36
|
expect(Pheme.configuration.sns_client).to receive(:publish).with({
|
37
37
|
topic_arn: "arn:aws:sns:whatever",
|
38
38
|
message: { id: "id-0", status: "complete" }.to_json,
|
39
|
+
message_attributes: nil,
|
39
40
|
})
|
40
41
|
expect(Pheme.configuration.sns_client).to receive(:publish).with({
|
41
42
|
topic_arn: "arn:aws:sns:whatever",
|
42
43
|
message: { id: "id-1", status: "complete" }.to_json,
|
44
|
+
message_attributes: nil,
|
43
45
|
})
|
44
46
|
subject.publish_events
|
45
47
|
end
|
@@ -54,6 +56,7 @@ describe Pheme::TopicPublisher do
|
|
54
56
|
expect(Pheme.configuration.sns_client).to receive(:publish).with({
|
55
57
|
topic_arn: topic_arn,
|
56
58
|
message: message,
|
59
|
+
message_attributes: nil,
|
57
60
|
})
|
58
61
|
subject.publish(message)
|
59
62
|
end
|
@@ -65,6 +68,7 @@ describe Pheme::TopicPublisher do
|
|
65
68
|
expect(sns_client).to receive(:publish).with({
|
66
69
|
topic_arn: topic_arn,
|
67
70
|
message: message,
|
71
|
+
message_attributes: nil,
|
68
72
|
})
|
69
73
|
subject.publish(message, sns_client: sns_client)
|
70
74
|
end
|
@@ -89,6 +93,7 @@ describe Pheme::TopicPublisher do
|
|
89
93
|
with({
|
90
94
|
topic_arn: topic_arn,
|
91
95
|
message: compressed_message,
|
96
|
+
message_attributes: nil,
|
92
97
|
}),
|
93
98
|
)
|
94
99
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pheme
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 4.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Peter Graham
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-01-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -98,16 +98,16 @@ dependencies:
|
|
98
98
|
name: coveralls
|
99
99
|
requirement: !ruby/object:Gem::Requirement
|
100
100
|
requirements:
|
101
|
-
- - "
|
101
|
+
- - "~>"
|
102
102
|
- !ruby/object:Gem::Version
|
103
|
-
version: '0'
|
103
|
+
version: '0.8'
|
104
104
|
type: :development
|
105
105
|
prerelease: false
|
106
106
|
version_requirements: !ruby/object:Gem::Requirement
|
107
107
|
requirements:
|
108
|
-
- - "
|
108
|
+
- - "~>"
|
109
109
|
- !ruby/object:Gem::Version
|
110
|
-
version: '0'
|
110
|
+
version: '0.8'
|
111
111
|
- !ruby/object:Gem::Dependency
|
112
112
|
name: git
|
113
113
|
requirement: !ruby/object:Gem::Requirement
|
@@ -240,6 +240,7 @@ files:
|
|
240
240
|
- LICENSE
|
241
241
|
- README.md
|
242
242
|
- Rakefile
|
243
|
+
- catalog-info.yaml
|
243
244
|
- lib/pheme.rb
|
244
245
|
- lib/pheme/compression.rb
|
245
246
|
- lib/pheme/configuration.rb
|
@@ -252,6 +253,7 @@ files:
|
|
252
253
|
- lib/pheme/topic_publisher.rb
|
253
254
|
- lib/pheme/version.rb
|
254
255
|
- pheme.gemspec
|
256
|
+
- sonar-project.properties
|
255
257
|
- spec/configuration_spec.rb
|
256
258
|
- spec/logger_spec.rb
|
257
259
|
- spec/message_handler_spec.rb
|