pheme 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 +4 -4
- data/.rubocop.yml +0 -37
- data/.rubocop_todo.yml +40 -21
- data/CHANGELOG.md +6 -0
- data/lib/pheme/queue_poller.rb +31 -3
- data/lib/pheme/version.rb +1 -1
- data/spec/queue_poller_spec.rb +78 -7
- data/spec/spec_helper.rb +2 -2
- data/spec/support/example_queue_poller_with_inlined_handler.rb +5 -0
- data/spec/support/example_queue_poller_with_message_handler.rb +3 -0
- metadata +7 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 290bb6b78fadf5e1dbd173c9c8bc1a6cd2cbd31f5d9058714ce4f2f77085cec7
|
4
|
+
data.tar.gz: f176ebff0f18a9cf36fade1cf6c169ad2c606116719d9cf206089c4d86a0553a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9ae6f12316cf6a777935078f322829b163603a2423672d8ef6b18ce4c0c64575cd66b22e218fc442547b34c25a8d6f9e9e6bc1b36fa6d97e45b48f5c29a78d4a
|
7
|
+
data.tar.gz: 8e35c281558aa4e72a9cfaf96cfe35f7d33929ccb61cf98ee48c21befd27587c2c7d31416e65a92c900f3bac4221511d5f039fe53e1c5cfafccbf27d85967a16
|
data/.rubocop.yml
CHANGED
@@ -7,40 +7,3 @@ inherit_gem:
|
|
7
7
|
AllCops:
|
8
8
|
# Specify your target Ruby version here (only major/minor versions):
|
9
9
|
TargetRubyVersion: 2.4
|
10
|
-
Exclude:
|
11
|
-
- 'bin/**/*'
|
12
|
-
- 'examples/**/*'
|
13
|
-
- 'tmp/**/*'
|
14
|
-
- 'vendor/**/*'
|
15
|
-
|
16
|
-
# This configuration was generated by
|
17
|
-
# `rubocop --auto-gen-config`
|
18
|
-
# on 2019-02-14 09:34:30 -0500 using RuboCop version 0.64.0.
|
19
|
-
# The point is for the user to remove these configuration records
|
20
|
-
# one by one as the offenses are removed from the code base.
|
21
|
-
# Note that changes in the inspected code, or installation of new
|
22
|
-
# versions of RuboCop, may require this file to be generated again.
|
23
|
-
|
24
|
-
# Offense count: 1
|
25
|
-
Metrics/AbcSize:
|
26
|
-
Max: 22
|
27
|
-
|
28
|
-
# Offense count: 8
|
29
|
-
# Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns.
|
30
|
-
# URISchemes: http, https
|
31
|
-
Metrics/LineLength:
|
32
|
-
Max: 147
|
33
|
-
|
34
|
-
# Offense count: 4
|
35
|
-
# Configuration parameters: CountComments, ExcludedMethods.
|
36
|
-
Metrics/MethodLength:
|
37
|
-
Max: 22
|
38
|
-
|
39
|
-
RSpec/FilePath:
|
40
|
-
Enabled: false
|
41
|
-
|
42
|
-
# Offense count: 1
|
43
|
-
# Configuration parameters: MinBodyLength.
|
44
|
-
Style/GuardClause:
|
45
|
-
Exclude:
|
46
|
-
- 'lib/pheme/queue_poller.rb'
|
data/.rubocop_todo.yml
CHANGED
@@ -1,20 +1,39 @@
|
|
1
1
|
# This configuration was generated by
|
2
2
|
# `rubocop --auto-gen-config`
|
3
|
-
# on 2019-
|
3
|
+
# on 2019-07-09 13:48:32 -0400 using RuboCop version 0.72.0.
|
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:
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
9
|
+
# Offense count: 2
|
10
|
+
Metrics/AbcSize:
|
11
|
+
Max: 22
|
12
|
+
|
13
|
+
# Offense count: 1
|
14
|
+
# Configuration parameters: CountComments.
|
15
|
+
Metrics/ClassLength:
|
16
|
+
Max: 164
|
17
|
+
|
18
|
+
# Offense count: 1
|
19
|
+
Metrics/CyclomaticComplexity:
|
20
|
+
Max: 10
|
21
|
+
|
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
|
+
# Offense count: 3
|
30
|
+
# Configuration parameters: CountComments, ExcludedMethods.
|
31
|
+
Metrics/MethodLength:
|
32
|
+
Max: 28
|
33
|
+
|
34
|
+
# Offense count: 1
|
35
|
+
Metrics/PerceivedComplexity:
|
36
|
+
Max: 11
|
18
37
|
|
19
38
|
# Offense count: 5
|
20
39
|
# Configuration parameters: CustomTransform, IgnoreMethods.
|
@@ -26,10 +45,10 @@ RSpec/FilePath:
|
|
26
45
|
- 'spec/message_type/aws_event_spec.rb'
|
27
46
|
- 'spec/message_type/sns_message_spec.rb'
|
28
47
|
- 'spec/queue_poller_spec.rb'
|
29
|
-
- 'spec/rollbar_spec.rb'
|
30
48
|
- 'spec/topic_publisher_spec.rb'
|
49
|
+
- 'spec/rollbar_spec.rb'
|
31
50
|
- 'spec/version_spec.rb'
|
32
|
-
|
51
|
+
|
33
52
|
# Offense count: 14
|
34
53
|
# Configuration parameters: EnforcedStyle.
|
35
54
|
# SupportedStyles: have_received, receive
|
@@ -40,14 +59,14 @@ RSpec/MessageSpies:
|
|
40
59
|
- 'spec/rollbar_spec.rb'
|
41
60
|
- 'spec/topic_publisher_spec.rb'
|
42
61
|
|
43
|
-
# Offense count:
|
44
|
-
# Configuration parameters:
|
45
|
-
RSpec/
|
62
|
+
# Offense count: 2
|
63
|
+
# Configuration parameters: IgnoreNameless, IgnoreSymbolicNames.
|
64
|
+
RSpec/VerifiedDoubles:
|
46
65
|
Exclude:
|
47
|
-
- 'spec/configuration_spec.rb'
|
48
|
-
- 'spec/logger_spec.rb'
|
49
|
-
- 'spec/message_handler_spec.rb'
|
50
|
-
- 'spec/message_type/sns_message_spec.rb'
|
51
66
|
- 'spec/queue_poller_spec.rb'
|
52
|
-
|
53
|
-
|
67
|
+
|
68
|
+
# Offense count: 2
|
69
|
+
# Configuration parameters: MinBodyLength.
|
70
|
+
Style/GuardClause:
|
71
|
+
Exclude:
|
72
|
+
- 'lib/pheme/queue_poller.rb'
|
data/CHANGELOG.md
CHANGED
@@ -4,6 +4,12 @@ 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
|
+
## 3.3.0 - 2019-07-09
|
8
|
+
### Added
|
9
|
+
- Add more friendly options for initializing queue pollers by either:
|
10
|
+
- passing the message handler class; or
|
11
|
+
- providing a handler block
|
12
|
+
|
7
13
|
## 3.2.0 - 2019-05-29
|
8
14
|
### Added
|
9
15
|
- Support for Pheme::TopicPublisher to publish to an explicit SNS client.
|
data/lib/pheme/queue_poller.rb
CHANGED
@@ -6,7 +6,15 @@ module Pheme
|
|
6
6
|
|
7
7
|
attr_accessor :queue_url, :queue_poller, :connection_pool_block, :format, :max_messages, :poller_configuration
|
8
8
|
|
9
|
-
def initialize(queue_url:,
|
9
|
+
def initialize(queue_url:,
|
10
|
+
connection_pool_block: false,
|
11
|
+
max_messages: nil,
|
12
|
+
format: :json,
|
13
|
+
poller_configuration: {},
|
14
|
+
sqs_client: nil,
|
15
|
+
idle_timeout: nil,
|
16
|
+
message_handler: nil,
|
17
|
+
&block_message_handler)
|
10
18
|
raise ArgumentError, "must specify non-nil queue_url" if queue_url.blank?
|
11
19
|
|
12
20
|
@queue_url = queue_url
|
@@ -22,6 +30,20 @@ module Pheme
|
|
22
30
|
skip_delete: true, # manually delete messages
|
23
31
|
}.merge(poller_configuration || {})
|
24
32
|
|
33
|
+
@poller_configuration[:idle_timeout] = idle_timeout unless idle_timeout.nil?
|
34
|
+
|
35
|
+
if message_handler
|
36
|
+
if message_handler.ancestors.include?(Pheme::MessageHandler)
|
37
|
+
@message_handler = message_handler
|
38
|
+
else
|
39
|
+
raise ArgumentError, 'Invalid message handler, must inherit from Pheme::MessageHandler'
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
@block_message_handler = block_message_handler
|
44
|
+
|
45
|
+
raise ArgumentError, 'only provide a message_handler or a block, not both' if @message_handler && @block_message_handler
|
46
|
+
|
25
47
|
if max_messages
|
26
48
|
queue_poller.before_request do |stats|
|
27
49
|
throw :stop_polling if stats.received_message_count >= max_messages
|
@@ -103,8 +125,14 @@ module Pheme
|
|
103
125
|
RecursiveOpenStruct.new({ wrapper: parsed_body }, recurse_over_arrays: true).wrapper
|
104
126
|
end
|
105
127
|
|
106
|
-
def handle(
|
107
|
-
|
128
|
+
def handle(message, metadata)
|
129
|
+
if @message_handler
|
130
|
+
@message_handler.new(message: message, metadata: metadata).handle
|
131
|
+
elsif @block_message_handler
|
132
|
+
@block_message_handler.call(message, metadata)
|
133
|
+
else
|
134
|
+
raise NotImplementedError
|
135
|
+
end
|
108
136
|
end
|
109
137
|
|
110
138
|
private
|
data/lib/pheme/version.rb
CHANGED
data/spec/queue_poller_spec.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
describe Pheme::QueuePoller do
|
2
|
+
let(:valid_queue_poller) { ExampleQueuePoller.new(queue_url: queue_url) }
|
2
3
|
let(:queue_url) { "https://sqs.us-east-1.amazonaws.com/whatever" }
|
3
4
|
let(:timestamp) { '2018-04-17T21:45:05.915Z' }
|
4
5
|
|
@@ -10,10 +11,9 @@ describe Pheme::QueuePoller do
|
|
10
11
|
end
|
11
12
|
let(:message) { nil }
|
12
13
|
let(:message_id) { SecureRandom.uuid }
|
13
|
-
let(:poller) { ExampleQueuePoller.new(queue_url: queue_url, format: format) }
|
14
14
|
|
15
15
|
context 'base poller' do
|
16
|
-
subject { described_class.new(queue_url:
|
16
|
+
subject { described_class.new(queue_url: queue_url).handle(nil, nil) }
|
17
17
|
|
18
18
|
it 'does not implement handle' do
|
19
19
|
expect { subject }.to raise_error(NotImplementedError)
|
@@ -23,7 +23,7 @@ describe Pheme::QueuePoller do
|
|
23
23
|
describe ".new" do
|
24
24
|
context "when initialized with valid params" do
|
25
25
|
it "does not raise an error" do
|
26
|
-
expect {
|
26
|
+
expect { valid_queue_poller }.not_to raise_error
|
27
27
|
end
|
28
28
|
end
|
29
29
|
|
@@ -35,7 +35,7 @@ describe Pheme::QueuePoller do
|
|
35
35
|
|
36
36
|
context "when initialized with max_messages" do
|
37
37
|
it "sets max_messages" do
|
38
|
-
expect(ExampleQueuePoller.new(queue_url:
|
38
|
+
expect(ExampleQueuePoller.new(queue_url: queue_url, max_messages: 5).max_messages).to eq(5)
|
39
39
|
end
|
40
40
|
end
|
41
41
|
|
@@ -43,13 +43,13 @@ describe Pheme::QueuePoller do
|
|
43
43
|
let(:sqs_client) { Object.new }
|
44
44
|
|
45
45
|
it "sets custom sqs_client" do
|
46
|
-
expect(Aws::SQS::QueuePoller).to receive(:new).with(
|
47
|
-
ExampleQueuePoller.new(queue_url:
|
46
|
+
expect(Aws::SQS::QueuePoller).to receive(:new).with(queue_url, client: sqs_client)
|
47
|
+
ExampleQueuePoller.new(queue_url: queue_url, sqs_client: sqs_client)
|
48
48
|
end
|
49
49
|
end
|
50
50
|
|
51
51
|
context 'received too many messages' do
|
52
|
-
subject { described_class.new(queue_url:
|
52
|
+
subject { described_class.new(queue_url: queue_url, max_messages: max_messages) }
|
53
53
|
|
54
54
|
let(:aws_poller) { instance_double('Aws::SQS::QueuePoller') }
|
55
55
|
let(:max_messages) { 50 }
|
@@ -63,11 +63,82 @@ describe Pheme::QueuePoller do
|
|
63
63
|
expect { subject }.to raise_error(UncaughtThrowError, /stop_polling/)
|
64
64
|
end
|
65
65
|
end
|
66
|
+
|
67
|
+
context 'when given an idle_timeout' do
|
68
|
+
subject { ExampleQueuePoller.new(queue_url: queue_url, idle_timeout: idle_timeout).poller_configuration[:idle_timeout] }
|
69
|
+
|
70
|
+
context 'when given a number' do
|
71
|
+
let(:idle_timeout) { 5 }
|
72
|
+
|
73
|
+
it { is_expected.to eq(5) }
|
74
|
+
end
|
75
|
+
|
76
|
+
context 'when given nil' do
|
77
|
+
let(:idle_timeout) { nil }
|
78
|
+
|
79
|
+
it { is_expected.to eq(20) }
|
80
|
+
end
|
81
|
+
|
82
|
+
context 'when given false' do
|
83
|
+
let(:idle_timeout) { false }
|
84
|
+
|
85
|
+
it { is_expected.to be(false) }
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
context 'when handling messages' do
|
90
|
+
context 'when doing it the old way, via the handle function' do
|
91
|
+
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
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
context 'when given a message_handler as parameter' do
|
97
|
+
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
|
+
end
|
100
|
+
|
101
|
+
it 'uses default when given invalid message_handler' do
|
102
|
+
expect { described_class.new(queue_url: queue_url, message_handler: Hash) }.to raise_error(ArgumentError)
|
103
|
+
end
|
104
|
+
|
105
|
+
it 'uses handler when given one' do
|
106
|
+
mock_handler = double('MessageHandler')
|
107
|
+
allow(mock_handler).to receive(:handle)
|
108
|
+
allow(ExampleMessageHandler).to receive(:new).with(message: 'message', metadata: 'metadata').and_return(mock_handler)
|
109
|
+
|
110
|
+
described_class.new(queue_url: queue_url, message_handler: ExampleMessageHandler).handle('message', 'metadata')
|
111
|
+
expect(mock_handler).to have_received(:handle).once
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
context 'when given a message_handler as block' do
|
116
|
+
it 'uses handler when given one' do
|
117
|
+
mock_handler = spy('MessageHandler')
|
118
|
+
|
119
|
+
poller = described_class.new(queue_url: queue_url) do |message, metadata|
|
120
|
+
mock_handler.process(message, metadata)
|
121
|
+
end
|
122
|
+
poller.handle('message', 'metadata')
|
123
|
+
|
124
|
+
expect(mock_handler).to have_received(:process).with('message', 'metadata').once
|
125
|
+
end
|
126
|
+
|
127
|
+
it 'fails on invalid handler' do
|
128
|
+
expect do
|
129
|
+
described_class.new(queue_url: queue_url, message_handler: ExampleMessageHandler) { raise Error('should never happen') }
|
130
|
+
end.to raise_error(ArgumentError, 'only provide a message_handler or a block, not both')
|
131
|
+
end
|
132
|
+
end
|
133
|
+
end
|
66
134
|
end
|
67
135
|
|
68
136
|
describe "#parse_body" do
|
69
137
|
subject { poller.parse_body(queue_message) }
|
70
138
|
|
139
|
+
let(:format) { nil }
|
140
|
+
let(:poller) { described_class.new(queue_url: queue_url, format: format) }
|
141
|
+
|
71
142
|
context "message is JSON string" do
|
72
143
|
let(:format) { :json }
|
73
144
|
let!(:message) { { test: 'test' }.to_json }
|
data/spec/spec_helper.rb
CHANGED
@@ -16,8 +16,6 @@ require 'pp'
|
|
16
16
|
|
17
17
|
require './lib/pheme'
|
18
18
|
|
19
|
-
Dir["./spec/support/**/*.rb"].each { |f| require f }
|
20
|
-
|
21
19
|
RSpec.configure do |config|
|
22
20
|
config.filter_run :focus
|
23
21
|
config.run_all_when_everything_filtered = true
|
@@ -36,3 +34,5 @@ def use_default_configuration!
|
|
36
34
|
config.logger = Logger.new(nil)
|
37
35
|
end
|
38
36
|
end
|
37
|
+
|
38
|
+
Dir["./spec/support/**/*.rb"].each { |f| require f }
|
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: 3.
|
4
|
+
version: 3.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Peter Graham
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-
|
11
|
+
date: 2019-07-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -264,6 +264,8 @@ files:
|
|
264
264
|
- spec/support/example_message_handler.rb
|
265
265
|
- spec/support/example_publisher.rb
|
266
266
|
- spec/support/example_queue_poller.rb
|
267
|
+
- spec/support/example_queue_poller_with_inlined_handler.rb
|
268
|
+
- spec/support/example_queue_poller_with_message_handler.rb
|
267
269
|
- spec/support/example_with_arn_publisher.rb
|
268
270
|
- spec/topic_publisher_spec.rb
|
269
271
|
- spec/version_spec.rb
|
@@ -286,8 +288,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
286
288
|
- !ruby/object:Gem::Version
|
287
289
|
version: '0'
|
288
290
|
requirements: []
|
289
|
-
|
290
|
-
rubygems_version: 2.7.6
|
291
|
+
rubygems_version: 3.0.3
|
291
292
|
signing_key:
|
292
293
|
specification_version: 4
|
293
294
|
summary: Ruby SNS publisher + SQS poller & message handler
|
@@ -304,6 +305,8 @@ test_files:
|
|
304
305
|
- spec/support/example_message_handler.rb
|
305
306
|
- spec/support/example_publisher.rb
|
306
307
|
- spec/support/example_queue_poller.rb
|
308
|
+
- spec/support/example_queue_poller_with_inlined_handler.rb
|
309
|
+
- spec/support/example_queue_poller_with_message_handler.rb
|
307
310
|
- spec/support/example_with_arn_publisher.rb
|
308
311
|
- spec/topic_publisher_spec.rb
|
309
312
|
- spec/version_spec.rb
|