sqewer 4.1.0 → 4.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/DETAILS.md +1 -1
- data/lib/sqewer/connection.rb +29 -3
- data/lib/sqewer/version.rb +1 -1
- data/lib/sqewer/worker.rb +0 -1
- data/spec/sqewer/connection_spec.rb +9 -0
- data/spec/{conveyor_belt_spec.rb → sqewer_module_spec.rb} +0 -0
- data/sqewer.gemspec +4 -4
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d580e81c48aeb4f31bf0069c603c3cee0413c51d
|
4
|
+
data.tar.gz: 87d546de3454ff297750d70d355a71c45340cc0a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4be05bef37befcb1e3f49021be38af632bbb4af52bfac17a4bc66fa9f81bca65406416538a59e6c94faac584f6d60884e43a46547cc5c96a9e900cd8eef7532e
|
7
|
+
data.tar.gz: 9bcf12c6ff462a7ca49659077193c1b95568872c4dd38f8444899000434cf8ce83d79e555bfd7e6226c4b18f9b2fefb72cc3feec28687b65c3047fe0b7858965
|
data/DETAILS.md
CHANGED
data/lib/sqewer/connection.rb
CHANGED
@@ -40,7 +40,6 @@ class Sqewer::Connection
|
|
40
40
|
#
|
41
41
|
# @return [Array<Message>] an array of Message objects
|
42
42
|
def receive_messages
|
43
|
-
client = ::Aws::SQS::Client.new
|
44
43
|
response = client.receive_message(queue_url: @queue_url,
|
45
44
|
wait_time_seconds: DEFAULT_TIMEOUT_SECONDS, max_number_of_messages: 10)
|
46
45
|
response.messages.map do | message |
|
@@ -58,6 +57,7 @@ class Sqewer::Connection
|
|
58
57
|
send_multiple_messages {|via| via.send_message(message_body, **kwargs_for_send) }
|
59
58
|
end
|
60
59
|
|
60
|
+
# Stores the messages for the SQS queue (both deletes and sends), and yields them in allowed batch sizes
|
61
61
|
class MessageBuffer < Struct.new(:messages)
|
62
62
|
MAX_RECORDS = 10
|
63
63
|
def initialize
|
@@ -68,6 +68,7 @@ class Sqewer::Connection
|
|
68
68
|
end
|
69
69
|
end
|
70
70
|
|
71
|
+
# Saves the messages to send to the SQS queue
|
71
72
|
class SendBuffer < MessageBuffer
|
72
73
|
def send_message(message_body, **kwargs_for_send)
|
73
74
|
# The "id" is only valid _within_ the request, and is used when
|
@@ -78,6 +79,7 @@ class Sqewer::Connection
|
|
78
79
|
end
|
79
80
|
end
|
80
81
|
|
82
|
+
# Saves the receipt handles to batch-delete from the SQS queue
|
81
83
|
class DeleteBuffer < MessageBuffer
|
82
84
|
def delete_message(receipt_handle)
|
83
85
|
# The "id" is only valid _within_ the request, and is used when
|
@@ -94,7 +96,6 @@ class Sqewer::Connection
|
|
94
96
|
def send_multiple_messages
|
95
97
|
buffer = SendBuffer.new
|
96
98
|
yield(buffer)
|
97
|
-
client = ::Aws::SQS::Client.new
|
98
99
|
buffer.each_batch do | batch |
|
99
100
|
resp = client.send_message_batch(queue_url: @queue_url, entries: batch)
|
100
101
|
failed = resp.failed
|
@@ -121,7 +122,6 @@ class Sqewer::Connection
|
|
121
122
|
buffer = DeleteBuffer.new
|
122
123
|
yield(buffer)
|
123
124
|
|
124
|
-
client = ::Aws::SQS::Client.new
|
125
125
|
buffer.each_batch do | batch |
|
126
126
|
resp = client.delete_message_batch(queue_url: @queue_url, entries: batch)
|
127
127
|
failed = resp.failed
|
@@ -131,4 +131,30 @@ class Sqewer::Connection
|
|
131
131
|
end
|
132
132
|
end
|
133
133
|
end
|
134
|
+
|
135
|
+
private
|
136
|
+
|
137
|
+
class RetryWrapper < Struct.new(:sqs_client)
|
138
|
+
MAX_RETRIES = 1000
|
139
|
+
# Provide retrying wrappers for all the methods of Aws::SQS::Client that we actually use
|
140
|
+
[:delete_message_batch, :send_message_batch, :receive_message].each do |retriable_method_name|
|
141
|
+
define_method(retriable_method_name) do |*args, **kwargs|
|
142
|
+
tries = 1
|
143
|
+
begin
|
144
|
+
sqs_client.public_send(retriable_method_name, *args, **kwargs)
|
145
|
+
rescue Seahorse::Client::NetworkingError => e
|
146
|
+
if (tries += 1) >= MAX_RETRIES
|
147
|
+
raise(e)
|
148
|
+
else
|
149
|
+
sleep 0.5
|
150
|
+
retry
|
151
|
+
end
|
152
|
+
end
|
153
|
+
end
|
154
|
+
end
|
155
|
+
end
|
156
|
+
|
157
|
+
def client
|
158
|
+
@client ||= RetryWrapper.new(Aws::SQS::Client.new)
|
159
|
+
end
|
134
160
|
end
|
data/lib/sqewer/version.rb
CHANGED
data/lib/sqewer/worker.rb
CHANGED
@@ -189,7 +189,6 @@ class Sqewer::Worker
|
|
189
189
|
|
190
190
|
def handle_message(message)
|
191
191
|
return unless message.receipt_handle
|
192
|
-
Thread.current[:queue_messsage] = '%s...' %message.body[0..32]
|
193
192
|
return @connection.delete_message(message.receipt_handle) unless message.has_body?
|
194
193
|
@isolator.perform(self, message)
|
195
194
|
# The message delete happens within the Isolator
|
@@ -29,6 +29,8 @@ describe Sqewer::Connection do
|
|
29
29
|
expect(conn).to receive(:send_multiple_messages).and_call_original
|
30
30
|
conn.send_message('abcdef', delay_seconds: 5)
|
31
31
|
end
|
32
|
+
|
33
|
+
it 'retries on networking errors'
|
32
34
|
end
|
33
35
|
|
34
36
|
describe '#send_multiple_messages' do
|
@@ -69,6 +71,9 @@ describe Sqewer::Connection do
|
|
69
71
|
end
|
70
72
|
}.to raise_error(/messages failed to send/)
|
71
73
|
end
|
74
|
+
|
75
|
+
it 'retries on networking errors'
|
76
|
+
|
72
77
|
end
|
73
78
|
|
74
79
|
describe '#delete_message' do
|
@@ -112,6 +117,8 @@ describe Sqewer::Connection do
|
|
112
117
|
end
|
113
118
|
}.to raise_error(/messages failed to delete/)
|
114
119
|
end
|
120
|
+
|
121
|
+
it 'retries on networking errors'
|
115
122
|
end
|
116
123
|
|
117
124
|
describe '#receive_messages' do
|
@@ -132,5 +139,7 @@ describe Sqewer::Connection do
|
|
132
139
|
messages = s.receive_messages
|
133
140
|
expect(messages.length).to eq(5)
|
134
141
|
end
|
142
|
+
|
143
|
+
it 'retries on networking errors'
|
135
144
|
end
|
136
145
|
end
|
File without changes
|
data/sqewer.gemspec
CHANGED
@@ -2,16 +2,16 @@
|
|
2
2
|
# DO NOT EDIT THIS FILE DIRECTLY
|
3
3
|
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
4
|
# -*- encoding: utf-8 -*-
|
5
|
-
# stub: sqewer 4.
|
5
|
+
# stub: sqewer 4.2.0 ruby lib
|
6
6
|
|
7
7
|
Gem::Specification.new do |s|
|
8
8
|
s.name = "sqewer"
|
9
|
-
s.version = "4.
|
9
|
+
s.version = "4.2.0"
|
10
10
|
|
11
11
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
12
12
|
s.require_paths = ["lib"]
|
13
13
|
s.authors = ["Julik Tarkhanov"]
|
14
|
-
s.date = "2016-02-
|
14
|
+
s.date = "2016-02-12"
|
15
15
|
s.description = "Process jobs from SQS"
|
16
16
|
s.email = "me@julik.nl"
|
17
17
|
s.extra_rdoc_files = [
|
@@ -44,7 +44,6 @@ Gem::Specification.new do |s|
|
|
44
44
|
"lib/sqewer/submitter.rb",
|
45
45
|
"lib/sqewer/version.rb",
|
46
46
|
"lib/sqewer/worker.rb",
|
47
|
-
"spec/conveyor_belt_spec.rb",
|
48
47
|
"spec/spec_helper.rb",
|
49
48
|
"spec/sqewer/atomic_counter_spec.rb",
|
50
49
|
"spec/sqewer/cli_app.rb",
|
@@ -56,6 +55,7 @@ Gem::Specification.new do |s|
|
|
56
55
|
"spec/sqewer/simple_job_spec.rb",
|
57
56
|
"spec/sqewer/submitter_spec.rb",
|
58
57
|
"spec/sqewer/worker_spec.rb",
|
58
|
+
"spec/sqewer_module_spec.rb",
|
59
59
|
"sqewer.gemspec"
|
60
60
|
]
|
61
61
|
s.homepage = "https://gitlab.wetransfer.net/julik/sqewer"
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sqewer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 4.
|
4
|
+
version: 4.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Julik Tarkhanov
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-02-
|
11
|
+
date: 2016-02-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: aws-sdk
|
@@ -225,7 +225,6 @@ files:
|
|
225
225
|
- lib/sqewer/submitter.rb
|
226
226
|
- lib/sqewer/version.rb
|
227
227
|
- lib/sqewer/worker.rb
|
228
|
-
- spec/conveyor_belt_spec.rb
|
229
228
|
- spec/spec_helper.rb
|
230
229
|
- spec/sqewer/atomic_counter_spec.rb
|
231
230
|
- spec/sqewer/cli_app.rb
|
@@ -237,6 +236,7 @@ files:
|
|
237
236
|
- spec/sqewer/simple_job_spec.rb
|
238
237
|
- spec/sqewer/submitter_spec.rb
|
239
238
|
- spec/sqewer/worker_spec.rb
|
239
|
+
- spec/sqewer_module_spec.rb
|
240
240
|
- sqewer.gemspec
|
241
241
|
homepage: https://gitlab.wetransfer.net/julik/sqewer
|
242
242
|
licenses:
|