pheme 3.3.3 → 4.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.circleci/config.yml +15 -11
- data/.rubocop_todo.yml +24 -17
- data/CHANGELOG.md +20 -0
- data/README.md +6 -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 +33 -6
- 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 +69 -10
- 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
- data/spec/version_spec.rb +1 -1
- 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: 0a03bd21407e73fb60ef72e1802d45683fe8e5fb20017f5144d2a6fd5a34b59e
|
|
4
|
+
data.tar.gz: fd9e6b59b514c56700ded3dc91a654cea4fc0fc132c32cfd9496deea30688ab0
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: e69e7edc5eacbe3d6e81d2e478c7963acf878a44f970f7a8ebd0b1cfa91f2077132bf2f137e6fe13c82168170ac9e6258b6c3b78c7e7cb5caea5a9a8c9874345
|
|
7
|
+
data.tar.gz: 62ceeeec4b07913d09cd22d8e28b57e6fe19e72d62e2fa658e099ccd8ffea54753f1db71f1249e6d03366dc16c443ea0d2ff31601324f81d06b0f0e628fd925c
|
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,26 @@ 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.3 - 2021-03-08
|
|
8
|
+
- Update documentation to include instructions on directly publishing to SQS
|
|
9
|
+
|
|
10
|
+
## 4.0.2 - 2020-12-17
|
|
11
|
+
- Bump local dev version, rubocop fixes, add backstage catalog file + sonarqube project settings
|
|
12
|
+
|
|
13
|
+
## 4.0.1 - 2020-03-23
|
|
14
|
+
### Fixes
|
|
15
|
+
- Fixes 4.0.0. Instead of expecting message attributes in the message from `poll`, retrieves them from the right place.
|
|
16
|
+
|
|
17
|
+
## 4.0.0 - 2020-03-18
|
|
18
|
+
### Breaking Changes
|
|
19
|
+
- Add the ability for SQS to receive message attributes
|
|
20
|
+
- `handle` function of `QueuePoller` now takes a third parameter `message_attributes`
|
|
21
|
+
- blocks or `MessageHandler`s passed to `QueuePoller` can use this `message_attributes`
|
|
22
|
+
|
|
23
|
+
## 3.4.0 - 2020-03-17
|
|
24
|
+
### Added
|
|
25
|
+
- Add the ability to pass message attributes to SNS
|
|
26
|
+
|
|
7
27
|
## 3.3.0 - 2019-07-09
|
|
8
28
|
### Added
|
|
9
29
|
- Add more friendly options for initializing queue pollers by either:
|
data/README.md
CHANGED
|
@@ -39,3 +39,9 @@ end
|
|
|
39
39
|
See https://github.com/wealthsimple/pheme/tree/master/spec/support for example implementations of each class.
|
|
40
40
|
|
|
41
41
|
TODO: write better usage instructions.
|
|
42
|
+
|
|
43
|
+
### Handling SQS messages
|
|
44
|
+
|
|
45
|
+
Pheme expects that the SQS messages it is handling will have first been published to an SNS topic
|
|
46
|
+
before being sent to the SQS queue. This means if the service publishing messages is publishing them
|
|
47
|
+
**directly** to the SQS queue, that service must nest the message payload underneath a `Message` property.
|
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]
|
|
@@ -105,6 +109,16 @@ module Pheme
|
|
|
105
109
|
{ timestamp: message_body['Timestamp'], topic_arn: message_body['TopicArn'] }
|
|
106
110
|
end
|
|
107
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
|
|
120
|
+
end
|
|
121
|
+
|
|
108
122
|
def get_metadata(message_body)
|
|
109
123
|
message_body.except('Message', 'Records')
|
|
110
124
|
end
|
|
@@ -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,21 @@ module Pheme
|
|
|
135
149
|
|
|
136
150
|
private
|
|
137
151
|
|
|
138
|
-
def
|
|
152
|
+
def coerce_message_attribute(value)
|
|
153
|
+
case value['Type']
|
|
154
|
+
when 'Binary', 'String'
|
|
155
|
+
value['Value']
|
|
156
|
+
when 'Number', 'String.Array'
|
|
157
|
+
JSON.parse(value['Value'])
|
|
158
|
+
else
|
|
159
|
+
Pheme.logger.info("Unsupported custom data type")
|
|
160
|
+
value["Value"]
|
|
161
|
+
end
|
|
162
|
+
end
|
|
163
|
+
|
|
164
|
+
def with_optional_connection_pool_block(&block)
|
|
139
165
|
if connection_pool_block
|
|
140
|
-
ActiveRecord::Base.connection_pool.with_connection
|
|
166
|
+
ActiveRecord::Base.connection_pool.with_connection(&block)
|
|
141
167
|
else
|
|
142
168
|
yield
|
|
143
169
|
end
|
|
@@ -192,4 +218,5 @@ module Pheme
|
|
|
192
218
|
}.to_json)
|
|
193
219
|
end
|
|
194
220
|
end
|
|
221
|
+
# rubocop:enable Metrics/ClassLength
|
|
195
222
|
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
|
@@ -14,7 +14,7 @@ describe Pheme::QueuePoller do
|
|
|
14
14
|
let(:message_id) { SecureRandom.uuid }
|
|
15
15
|
|
|
16
16
|
context 'base poller' do
|
|
17
|
-
subject { described_class.new(queue_url: queue_url).handle(nil, nil) }
|
|
17
|
+
subject { described_class.new(queue_url: queue_url).handle(nil, nil, nil) }
|
|
18
18
|
|
|
19
19
|
it 'does not implement handle' do
|
|
20
20
|
expect { subject }.to raise_error(NotImplementedError)
|
|
@@ -90,13 +90,13 @@ describe Pheme::QueuePoller do
|
|
|
90
90
|
context 'when handling messages' do
|
|
91
91
|
context 'when doing it the old way, via the handle function' do
|
|
92
92
|
it 'uses the handle function by default' do
|
|
93
|
-
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)
|
|
94
94
|
end
|
|
95
95
|
end
|
|
96
96
|
|
|
97
97
|
context 'when given a message_handler as parameter' do
|
|
98
98
|
it 'uses default when given nil' do
|
|
99
|
-
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)
|
|
100
100
|
end
|
|
101
101
|
|
|
102
102
|
it 'uses default when given invalid message_handler' do
|
|
@@ -106,9 +106,11 @@ describe Pheme::QueuePoller do
|
|
|
106
106
|
it 'uses handler when given one' do
|
|
107
107
|
mock_handler = double('MessageHandler')
|
|
108
108
|
allow(mock_handler).to receive(:handle)
|
|
109
|
-
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)
|
|
110
112
|
|
|
111
|
-
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')
|
|
112
114
|
expect(mock_handler).to have_received(:handle).once
|
|
113
115
|
end
|
|
114
116
|
end
|
|
@@ -117,12 +119,12 @@ describe Pheme::QueuePoller do
|
|
|
117
119
|
it 'uses handler when given one' do
|
|
118
120
|
mock_handler = spy('MessageHandler')
|
|
119
121
|
|
|
120
|
-
poller = described_class.new(queue_url: queue_url) do |message, metadata|
|
|
121
|
-
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)
|
|
122
124
|
end
|
|
123
|
-
poller.handle('message', 'metadata')
|
|
125
|
+
poller.handle('message', 'metadata', 'message_attributes')
|
|
124
126
|
|
|
125
|
-
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
|
|
126
128
|
end
|
|
127
129
|
|
|
128
130
|
it 'fails on invalid handler' do
|
|
@@ -134,6 +136,62 @@ describe Pheme::QueuePoller do
|
|
|
134
136
|
end
|
|
135
137
|
end
|
|
136
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
|
+
|
|
137
195
|
describe "#parse_body" do
|
|
138
196
|
subject { poller.parse_body(queue_message) }
|
|
139
197
|
|
|
@@ -305,6 +363,7 @@ describe Pheme::QueuePoller do
|
|
|
305
363
|
expect(ExampleMessageHandler).to receive(:new).with(
|
|
306
364
|
message: RecursiveOpenStruct.new(message),
|
|
307
365
|
metadata: { timestamp: timestamp, topic_arn: topic_arn },
|
|
366
|
+
message_attributes: {},
|
|
308
367
|
)
|
|
309
368
|
subject.poll
|
|
310
369
|
end
|
|
@@ -359,7 +418,7 @@ describe Pheme::QueuePoller do
|
|
|
359
418
|
|
|
360
419
|
let(:queue_message) { OpenStruct.new(body: { 'Records' => records }.to_json) }
|
|
361
420
|
let(:records) do
|
|
362
|
-
[{ 'eventVersion' => '2.0',
|
|
421
|
+
[{ 'eventVersion' => '2.0', eventSource: 'aws:s3' }]
|
|
363
422
|
end
|
|
364
423
|
|
|
365
424
|
before do
|
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
|
|
data/spec/version_spec.rb
CHANGED
|
@@ -4,7 +4,7 @@ describe Pheme do
|
|
|
4
4
|
def get_version(git, branch = 'HEAD')
|
|
5
5
|
git.grep('VERSION = ', 'lib/*/version.rb', { object: branch }).
|
|
6
6
|
map { |_sha, matches| matches.first[1] }.
|
|
7
|
-
map(
|
|
7
|
+
map { |version_string| parse_version(version_string) }.
|
|
8
8
|
reject(&:nil?).
|
|
9
9
|
first
|
|
10
10
|
end
|
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.3
|
|
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-03-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
|