eventq 2.0.0.rc1 → 2.0.0.rc2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +54 -24
- data/lib/eventq/aws.rb +1 -6
- data/lib/eventq/eventq_aws/aws_queue_worker.rb +17 -42
- data/lib/eventq/eventq_base/configuration.rb +2 -6
- data/lib/eventq/eventq_base/queue.rb +3 -0
- data/lib/eventq/eventq_base/serialization_providers.rb +2 -9
- data/lib/eventq/eventq_rabbitmq/rabbitmq_queue_client.rb +1 -6
- data/lib/eventq/eventq_rabbitmq/rabbitmq_queue_manager.rb +4 -12
- data/lib/eventq/eventq_rabbitmq/rabbitmq_queue_worker.rb +22 -56
- data/lib/eventq/queue_worker.rb +56 -1
- data/lib/eventq/rabbitmq.rb +2 -10
- metadata +19 -35
- data/lib/eventq/eventq_aws/README.md +0 -53
- data/lib/eventq/eventq_aws/jruby/aws_queue_worker.rb +0 -370
- data/lib/eventq/eventq_base/serialization_providers/jruby/oj/array_writer.rb +0 -20
- data/lib/eventq/eventq_base/serialization_providers/jruby/oj/attribute_writer.rb +0 -24
- data/lib/eventq/eventq_base/serialization_providers/jruby/oj/class_writer.rb +0 -20
- data/lib/eventq/eventq_base/serialization_providers/jruby/oj/date_time_writer.rb +0 -33
- data/lib/eventq/eventq_base/serialization_providers/jruby/oj/date_writer.rb +0 -22
- data/lib/eventq/eventq_base/serialization_providers/jruby/oj/hash_writer.rb +0 -18
- data/lib/eventq/eventq_base/serialization_providers/jruby/oj/rational_writer.rb +0 -20
- data/lib/eventq/eventq_base/serialization_providers/jruby/oj/serializer.rb +0 -17
- data/lib/eventq/eventq_base/serialization_providers/jruby/oj/time_writer.rb +0 -18
- data/lib/eventq/eventq_base/serialization_providers/jruby/oj/value_writer.rb +0 -16
- data/lib/eventq/eventq_base/serialization_providers/jruby/oj.rb +0 -10
- data/lib/eventq/eventq_base/serialization_providers/jruby/oj_serialization_provider.rb +0 -25
- data/lib/eventq/eventq_base/serialization_providers/jruby.rb +0 -2
- data/lib/eventq/eventq_rabbitmq/README.md +0 -36
- data/lib/eventq/eventq_rabbitmq/jruby/rabbitmq_queue_worker.rb +0 -367
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: eventq
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0.0.
|
4
|
+
version: 2.0.0.rc2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- SageOne
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-09-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -80,6 +80,20 @@ dependencies:
|
|
80
80
|
- - ">="
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: activesupport
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '4'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '4'
|
83
97
|
- !ruby/object:Gem::Dependency
|
84
98
|
name: aws-sdk
|
85
99
|
requirement: !ruby/object:Gem::Requirement
|
@@ -150,20 +164,6 @@ dependencies:
|
|
150
164
|
- - ">="
|
151
165
|
- !ruby/object:Gem::Version
|
152
166
|
version: '0'
|
153
|
-
- !ruby/object:Gem::Dependency
|
154
|
-
name: activesupport
|
155
|
-
requirement: !ruby/object:Gem::Requirement
|
156
|
-
requirements:
|
157
|
-
- - "~>"
|
158
|
-
- !ruby/object:Gem::Version
|
159
|
-
version: '4'
|
160
|
-
type: :runtime
|
161
|
-
prerelease: false
|
162
|
-
version_requirements: !ruby/object:Gem::Requirement
|
163
|
-
requirements:
|
164
|
-
- - "~>"
|
165
|
-
- !ruby/object:Gem::Version
|
166
|
-
version: '4'
|
167
167
|
- !ruby/object:Gem::Dependency
|
168
168
|
name: oj
|
169
169
|
requirement: !ruby/object:Gem::Requirement
|
@@ -192,7 +192,8 @@ dependencies:
|
|
192
192
|
- - ">="
|
193
193
|
- !ruby/object:Gem::Version
|
194
194
|
version: '0'
|
195
|
-
description:
|
195
|
+
description: EventQ is a pub/sub system that uses async notifications and message
|
196
|
+
queues
|
196
197
|
email:
|
197
198
|
- sageone@sage.com
|
198
199
|
executables: []
|
@@ -204,14 +205,12 @@ files:
|
|
204
205
|
- bin/setup
|
205
206
|
- lib/eventq.rb
|
206
207
|
- lib/eventq/aws.rb
|
207
|
-
- lib/eventq/eventq_aws/README.md
|
208
208
|
- lib/eventq/eventq_aws/aws_eventq_client.rb
|
209
209
|
- lib/eventq/eventq_aws/aws_queue_client.rb
|
210
210
|
- lib/eventq/eventq_aws/aws_queue_manager.rb
|
211
211
|
- lib/eventq/eventq_aws/aws_queue_worker.rb
|
212
212
|
- lib/eventq/eventq_aws/aws_status_checker.rb
|
213
213
|
- lib/eventq/eventq_aws/aws_subscription_manager.rb
|
214
|
-
- lib/eventq/eventq_aws/jruby/aws_queue_worker.rb
|
215
214
|
- lib/eventq/eventq_aws/sns.rb
|
216
215
|
- lib/eventq/eventq_aws/sqs.rb
|
217
216
|
- lib/eventq/eventq_base/configuration.rb
|
@@ -230,19 +229,6 @@ files:
|
|
230
229
|
- lib/eventq/eventq_base/queue_worker_contract.rb
|
231
230
|
- lib/eventq/eventq_base/serialization_providers.rb
|
232
231
|
- lib/eventq/eventq_base/serialization_providers/binary_serialization_provider.rb
|
233
|
-
- lib/eventq/eventq_base/serialization_providers/jruby.rb
|
234
|
-
- lib/eventq/eventq_base/serialization_providers/jruby/oj.rb
|
235
|
-
- lib/eventq/eventq_base/serialization_providers/jruby/oj/array_writer.rb
|
236
|
-
- lib/eventq/eventq_base/serialization_providers/jruby/oj/attribute_writer.rb
|
237
|
-
- lib/eventq/eventq_base/serialization_providers/jruby/oj/class_writer.rb
|
238
|
-
- lib/eventq/eventq_base/serialization_providers/jruby/oj/date_time_writer.rb
|
239
|
-
- lib/eventq/eventq_base/serialization_providers/jruby/oj/date_writer.rb
|
240
|
-
- lib/eventq/eventq_base/serialization_providers/jruby/oj/hash_writer.rb
|
241
|
-
- lib/eventq/eventq_base/serialization_providers/jruby/oj/rational_writer.rb
|
242
|
-
- lib/eventq/eventq_base/serialization_providers/jruby/oj/serializer.rb
|
243
|
-
- lib/eventq/eventq_base/serialization_providers/jruby/oj/time_writer.rb
|
244
|
-
- lib/eventq/eventq_base/serialization_providers/jruby/oj/value_writer.rb
|
245
|
-
- lib/eventq/eventq_base/serialization_providers/jruby/oj_serialization_provider.rb
|
246
232
|
- lib/eventq/eventq_base/serialization_providers/json_serialization_provider.rb
|
247
233
|
- lib/eventq/eventq_base/serialization_providers/oj_serialization_provider.rb
|
248
234
|
- lib/eventq/eventq_base/signature_providers.rb
|
@@ -250,9 +236,7 @@ files:
|
|
250
236
|
- lib/eventq/eventq_base/subscription_manager_contract.rb
|
251
237
|
- lib/eventq/eventq_base/version.rb
|
252
238
|
- lib/eventq/eventq_base/worker_id.rb
|
253
|
-
- lib/eventq/eventq_rabbitmq/README.md
|
254
239
|
- lib/eventq/eventq_rabbitmq/default_queue.rb
|
255
|
-
- lib/eventq/eventq_rabbitmq/jruby/rabbitmq_queue_worker.rb
|
256
240
|
- lib/eventq/eventq_rabbitmq/rabbitmq_eventq_client.rb
|
257
241
|
- lib/eventq/eventq_rabbitmq/rabbitmq_queue_client.rb
|
258
242
|
- lib/eventq/eventq_rabbitmq/rabbitmq_queue_manager.rb
|
@@ -285,5 +269,5 @@ rubyforge_project:
|
|
285
269
|
rubygems_version: 2.7.7
|
286
270
|
signing_key:
|
287
271
|
specification_version: 4
|
288
|
-
summary:
|
272
|
+
summary: EventQ is a pub/sub system that uses async notifications and message queues
|
289
273
|
test_files: []
|
@@ -1,53 +0,0 @@
|
|
1
|
-
# EventQ [AWS]
|
2
|
-
|
3
|
-
Welcome to EventQ. This gem contains the AWS implementations of the EventQ framework components.
|
4
|
-
|
5
|
-
## Installation
|
6
|
-
|
7
|
-
Add this line to your application:
|
8
|
-
|
9
|
-
```ruby
|
10
|
-
require 'eventq/aws'
|
11
|
-
```
|
12
|
-
|
13
|
-
## Development
|
14
|
-
|
15
|
-
After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
16
|
-
|
17
|
-
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
18
|
-
|
19
|
-
### Preparing the Docker images
|
20
|
-
|
21
|
-
Run the setup script of eventq_aws to build the environment. This will create the `eventq/aws` image.
|
22
|
-
|
23
|
-
$ cd script
|
24
|
-
$ ./setup.sh
|
25
|
-
|
26
|
-
### Running the tests
|
27
|
-
|
28
|
-
By default, the full test suite will run against the mock AWS services defined in the docker-compose.yml file.
|
29
|
-
|
30
|
-
If you want to run the tests with AWS directly, you will need an AWS account. Put your credentials into the `.aws.env` file in the parent directory.
|
31
|
-
|
32
|
-
$ cp ../.aws.env.template ../.aws.env
|
33
|
-
$ vi ../.aws.env
|
34
|
-
|
35
|
-
Run the whole test suite:
|
36
|
-
|
37
|
-
$ cd script
|
38
|
-
$ ./test.sh
|
39
|
-
|
40
|
-
You can run the specs that don't depend on an AWS account with:
|
41
|
-
|
42
|
-
$ cd script
|
43
|
-
$ ./test.sh --tag ~integration
|
44
|
-
|
45
|
-
## Contributing
|
46
|
-
|
47
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/sage/eventq. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
48
|
-
|
49
|
-
|
50
|
-
## License
|
51
|
-
|
52
|
-
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
53
|
-
|
@@ -1,370 +0,0 @@
|
|
1
|
-
require 'java'
|
2
|
-
java_import java.util.concurrent.Executors
|
3
|
-
module EventQ
|
4
|
-
module Amazon
|
5
|
-
class QueueWorker
|
6
|
-
include EventQ::WorkerId
|
7
|
-
|
8
|
-
APPROXIMATE_RECEIVE_COUNT = 'ApproximateReceiveCount'.freeze
|
9
|
-
MESSAGE = 'Message'.freeze
|
10
|
-
|
11
|
-
attr_accessor :is_running
|
12
|
-
|
13
|
-
def initialize
|
14
|
-
@is_running = false
|
15
|
-
|
16
|
-
@on_retry_exceeded_block = nil
|
17
|
-
@on_retry_block = nil
|
18
|
-
@on_error_block = nil
|
19
|
-
|
20
|
-
@hash_helper = HashKit::Helper.new
|
21
|
-
@serialization_provider_manager = EventQ::SerializationProviders::Manager.new
|
22
|
-
@signature_provider_manager = EventQ::SignatureProviders::Manager.new
|
23
|
-
|
24
|
-
@last_gc_flush = Time.now
|
25
|
-
@gc_flush_interval = 10
|
26
|
-
|
27
|
-
@queue_poll_wait = 10
|
28
|
-
end
|
29
|
-
|
30
|
-
def start(queue, options = {}, &block)
|
31
|
-
|
32
|
-
EventQ.logger.info("[#{self.class}] - Preparing to start listening for messages.")
|
33
|
-
|
34
|
-
configure(queue, options)
|
35
|
-
|
36
|
-
if options[:client] == nil
|
37
|
-
raise "[#{self.class}] - :client (QueueClient) must be specified."
|
38
|
-
end
|
39
|
-
|
40
|
-
raise "[#{self.class}] - Worker is already running." if running?
|
41
|
-
|
42
|
-
client = options[:client]
|
43
|
-
EventQ.logger.debug do
|
44
|
-
"[#{self.class} #start] - Listening for messages on queue: #{queue.name}, Queue Url: #{client.sqs_helper.get_queue_url(queue)}, Queue arn: #{client.sqs_helper.get_queue_arn(queue)}"
|
45
|
-
end
|
46
|
-
|
47
|
-
EventQ.logger.info("[#{self.class}] - Listening for messages.")
|
48
|
-
|
49
|
-
start_process(options, queue, block)
|
50
|
-
|
51
|
-
return true
|
52
|
-
end
|
53
|
-
|
54
|
-
def start_process(options, queue, block)
|
55
|
-
|
56
|
-
%w'INT TERM'.each do |sig|
|
57
|
-
Signal.trap(sig) {
|
58
|
-
stop
|
59
|
-
exit
|
60
|
-
}
|
61
|
-
end
|
62
|
-
|
63
|
-
@is_running = true
|
64
|
-
|
65
|
-
@executor = java.util.concurrent.Executors::newFixedThreadPool @thread_count
|
66
|
-
|
67
|
-
#loop through each thread count
|
68
|
-
@thread_count.times do
|
69
|
-
|
70
|
-
@executor.execute do
|
71
|
-
|
72
|
-
client = options[:client]
|
73
|
-
manager = EventQ::Amazon::QueueManager.new({ client: client })
|
74
|
-
|
75
|
-
#begin the queue loop for this thread
|
76
|
-
while true do
|
77
|
-
|
78
|
-
#check if the worker is still allowed to run and break out of thread loop if not
|
79
|
-
unless running?
|
80
|
-
break
|
81
|
-
end
|
82
|
-
|
83
|
-
if @executor.is_shutdown
|
84
|
-
break
|
85
|
-
end
|
86
|
-
|
87
|
-
has_message_received = thread_process_iteration(client, manager, queue, block)
|
88
|
-
|
89
|
-
gc_flush
|
90
|
-
|
91
|
-
if !has_message_received
|
92
|
-
EventQ.logger.debug { "[#{self.class}] - No message received." }
|
93
|
-
if @sleep > 0
|
94
|
-
EventQ.logger.debug { "[#{self.class}] - Sleeping for #{@sleep} seconds" }
|
95
|
-
sleep(@sleep)
|
96
|
-
end
|
97
|
-
end
|
98
|
-
|
99
|
-
end
|
100
|
-
|
101
|
-
end
|
102
|
-
|
103
|
-
end
|
104
|
-
|
105
|
-
if options.key?(:wait) && options[:wait] == true
|
106
|
-
while running? do end
|
107
|
-
end
|
108
|
-
|
109
|
-
end
|
110
|
-
|
111
|
-
def gc_flush
|
112
|
-
if Time.now - last_gc_flush > @gc_flush_interval
|
113
|
-
GC.start
|
114
|
-
@last_gc_flush = Time.now
|
115
|
-
end
|
116
|
-
end
|
117
|
-
|
118
|
-
def last_gc_flush
|
119
|
-
@last_gc_flush
|
120
|
-
end
|
121
|
-
|
122
|
-
def thread_process_iteration(client, manager, queue, block)
|
123
|
-
#get the queue
|
124
|
-
q = manager.get_queue(queue)
|
125
|
-
|
126
|
-
received = false
|
127
|
-
|
128
|
-
begin
|
129
|
-
|
130
|
-
#request a message from the queue
|
131
|
-
response = client.sqs.receive_message({
|
132
|
-
queue_url: q,
|
133
|
-
max_number_of_messages: 1,
|
134
|
-
wait_time_seconds: @queue_poll_wait,
|
135
|
-
attribute_names: [APPROXIMATE_RECEIVE_COUNT]
|
136
|
-
})
|
137
|
-
|
138
|
-
#check that a message was received
|
139
|
-
if response.messages.length > 0
|
140
|
-
received = true
|
141
|
-
begin
|
142
|
-
tag_processing_thread
|
143
|
-
process_message(response, client, queue, q, block)
|
144
|
-
ensure
|
145
|
-
untag_processing_thread
|
146
|
-
end
|
147
|
-
|
148
|
-
end
|
149
|
-
|
150
|
-
rescue => e
|
151
|
-
EventQ.log(:error, "[#{self.class}] - An unhandled error occurred. Error: #{e} | Backtrace: #{e.backtrace}")
|
152
|
-
call_on_error_block(error: e)
|
153
|
-
end
|
154
|
-
|
155
|
-
return received
|
156
|
-
end
|
157
|
-
|
158
|
-
def call_on_error_block(error:, message: nil)
|
159
|
-
if @on_error_block
|
160
|
-
EventQ.logger.debug { "[#{self.class}] - Executing on_error block." }
|
161
|
-
begin
|
162
|
-
@on_error_block.call(error, message)
|
163
|
-
rescue => e
|
164
|
-
EventQ.logger.error("[#{self.class}] - An error occurred executing the on_error block. Error: #{e}")
|
165
|
-
end
|
166
|
-
else
|
167
|
-
EventQ.logger.debug { "[#{self.class}] - No on_error block specified to execute." }
|
168
|
-
end
|
169
|
-
end
|
170
|
-
|
171
|
-
def call_on_retry_exceeded_block(message)
|
172
|
-
if @on_retry_exceeded_block != nil
|
173
|
-
EventQ.logger.debug { "[#{self.class}] - Executing on_retry_exceeded block." }
|
174
|
-
begin
|
175
|
-
@on_retry_exceeded_block.call(message)
|
176
|
-
rescue => e
|
177
|
-
EventQ.logger.error("[#{self.class}] - An error occurred executing the on_retry_exceeded block. Error: #{e}")
|
178
|
-
end
|
179
|
-
else
|
180
|
-
EventQ.logger.debug { "[#{self.class}] - No on_retry_exceeded block specified." }
|
181
|
-
end
|
182
|
-
end
|
183
|
-
|
184
|
-
def call_on_retry_block(message)
|
185
|
-
if @on_retry_block
|
186
|
-
EventQ.logger.debug { "[#{self.class}] - Executing on_retry block." }
|
187
|
-
begin
|
188
|
-
@on_retry_block.call(message, abort)
|
189
|
-
rescue => e
|
190
|
-
EventQ.logger.error("[#{self.class}] - An error occurred executing the on_retry block. Error: #{e}")
|
191
|
-
end
|
192
|
-
else
|
193
|
-
EventQ.logger.debug { "[#{self.class}] - No on_retry block specified." }
|
194
|
-
end
|
195
|
-
end
|
196
|
-
|
197
|
-
def stop
|
198
|
-
EventQ.logger.info("[#{self.class}] - Stopping.")
|
199
|
-
@is_running = false
|
200
|
-
@executor.shutdown
|
201
|
-
return true
|
202
|
-
end
|
203
|
-
|
204
|
-
def on_retry_exceeded(&block)
|
205
|
-
@retry_exceeded_block = block
|
206
|
-
end
|
207
|
-
|
208
|
-
def on_retry(&block)
|
209
|
-
@on_retry_block = block
|
210
|
-
return nil
|
211
|
-
end
|
212
|
-
|
213
|
-
def on_error(&block)
|
214
|
-
@on_error_block = block
|
215
|
-
return nil
|
216
|
-
end
|
217
|
-
|
218
|
-
def running?
|
219
|
-
return @is_running
|
220
|
-
end
|
221
|
-
|
222
|
-
def deserialize_message(payload)
|
223
|
-
provider = @serialization_provider_manager.get_provider(EventQ::Configuration.serialization_provider)
|
224
|
-
return provider.deserialize(payload)
|
225
|
-
end
|
226
|
-
|
227
|
-
def serialize_message(msg)
|
228
|
-
provider = @serialization_provider_manager.get_provider(EventQ::Configuration.serialization_provider)
|
229
|
-
return provider.serialize(msg)
|
230
|
-
end
|
231
|
-
|
232
|
-
private
|
233
|
-
|
234
|
-
def process_message(response, client, queue, q, block)
|
235
|
-
msg = response.messages[0]
|
236
|
-
retry_attempts = msg.attributes[APPROXIMATE_RECEIVE_COUNT].to_i - 1
|
237
|
-
|
238
|
-
#deserialize the message payload
|
239
|
-
payload = JSON.load(msg.body)
|
240
|
-
message = deserialize_message(payload[MESSAGE])
|
241
|
-
|
242
|
-
message_args = EventQ::MessageArgs.new(type: message.type,
|
243
|
-
retry_attempts: retry_attempts,
|
244
|
-
context: message.context,
|
245
|
-
content_type: message.content_type)
|
246
|
-
|
247
|
-
EventQ.logger.info("[#{self.class}] - Message received. Retry Attempts: #{retry_attempts}")
|
248
|
-
|
249
|
-
@signature_provider_manager.validate_signature(message: message, queue: queue)
|
250
|
-
|
251
|
-
if(!EventQ::NonceManager.is_allowed?(message.id))
|
252
|
-
EventQ.logger.info("[#{self.class}] - Duplicate Message received. Dropping message.")
|
253
|
-
client.sqs.delete_message({ queue_url: q, receipt_handle: msg.receipt_handle })
|
254
|
-
return false
|
255
|
-
end
|
256
|
-
|
257
|
-
#begin worker block for queue message
|
258
|
-
begin
|
259
|
-
|
260
|
-
block.call(message.content, message_args)
|
261
|
-
|
262
|
-
if message_args.abort == true
|
263
|
-
EventQ.logger.info("[#{self.class}] - Message aborted.")
|
264
|
-
else
|
265
|
-
#accept the message as processed
|
266
|
-
client.sqs.delete_message({ queue_url: q, receipt_handle: msg.receipt_handle })
|
267
|
-
EventQ.logger.info("[#{self.class}] - Message acknowledged.")
|
268
|
-
end
|
269
|
-
|
270
|
-
rescue => e
|
271
|
-
EventQ.logger.error("[#{self.class}] - An unhandled error happened while attempting to process a queue message. Error: #{e} | Backtrace: #{e.backtrace}")
|
272
|
-
error = true
|
273
|
-
call_on_error_block(error: e, message: message)
|
274
|
-
end
|
275
|
-
|
276
|
-
if message_args.abort || error
|
277
|
-
EventQ::NonceManager.failed(message.id)
|
278
|
-
reject_message(queue, client, msg, q, retry_attempts, message, message_args.abort)
|
279
|
-
else
|
280
|
-
EventQ::NonceManager.complete(message.id)
|
281
|
-
end
|
282
|
-
|
283
|
-
return true
|
284
|
-
end
|
285
|
-
|
286
|
-
def reject_message(queue, client, msg, q, retry_attempts, message, abort)
|
287
|
-
|
288
|
-
if !queue.allow_retry || retry_attempts >= queue.max_retry_attempts
|
289
|
-
|
290
|
-
EventQ.logger.info("[#{self.class}] - Message rejected removing from queue. Message: #{serialize_message(message)}")
|
291
|
-
|
292
|
-
#remove the message from the queue so that it does not get retried again
|
293
|
-
client.sqs.delete_message({ queue_url: q, receipt_handle: msg.receipt_handle })
|
294
|
-
|
295
|
-
if retry_attempts >= queue.max_retry_attempts
|
296
|
-
|
297
|
-
EventQ.logger.info("[#{self.class}] - Message retry attempt limit exceeded.")
|
298
|
-
call_on_retry_exceeded_block(message)
|
299
|
-
|
300
|
-
end
|
301
|
-
|
302
|
-
elsif queue.allow_retry
|
303
|
-
|
304
|
-
retry_attempts += 1
|
305
|
-
|
306
|
-
EventQ.logger.info("[#{self.class}] - Message rejected requesting retry. Attempts: #{retry_attempts}")
|
307
|
-
|
308
|
-
if queue.allow_retry_back_off == true
|
309
|
-
EventQ.logger.debug { "[#{self.class}] - Calculating message back off retry delay. Attempts: #{retry_attempts} * Delay: #{queue.retry_delay}" }
|
310
|
-
visibility_timeout = (queue.retry_delay * retry_attempts) / 1000
|
311
|
-
if visibility_timeout > (queue.max_retry_delay / 1000)
|
312
|
-
EventQ.logger.debug { "[#{self.class}] - Max message back off retry delay reached." }
|
313
|
-
visibility_timeout = queue.max_retry_delay / 1000
|
314
|
-
end
|
315
|
-
else
|
316
|
-
EventQ.logger.debug { "[#{self.class}] - Setting fixed retry delay for message." }
|
317
|
-
visibility_timeout = queue.retry_delay / 1000
|
318
|
-
end
|
319
|
-
|
320
|
-
if visibility_timeout > 43200
|
321
|
-
EventQ.logger.debug { "[#{self.class}] - AWS max visibility timeout of 12 hours has been exceeded. Setting message retry delay to 12 hours." }
|
322
|
-
visibility_timeout = 43200
|
323
|
-
end
|
324
|
-
|
325
|
-
EventQ.logger.debug { "[#{self.class}] - Sending message for retry. Message TTL: #{visibility_timeout}" }
|
326
|
-
client.sqs.change_message_visibility({
|
327
|
-
queue_url: q, # required
|
328
|
-
receipt_handle: msg.receipt_handle, # required
|
329
|
-
visibility_timeout: visibility_timeout.to_s, # required
|
330
|
-
})
|
331
|
-
|
332
|
-
call_on_retry_block(message)
|
333
|
-
|
334
|
-
end
|
335
|
-
|
336
|
-
end
|
337
|
-
|
338
|
-
def configure(queue, options = {})
|
339
|
-
|
340
|
-
@queue = queue
|
341
|
-
|
342
|
-
#default thread count
|
343
|
-
@thread_count = 5
|
344
|
-
if options.key?(:thread_count)
|
345
|
-
@thread_count = options[:thread_count]
|
346
|
-
end
|
347
|
-
|
348
|
-
#default sleep time in seconds
|
349
|
-
@sleep = 5
|
350
|
-
if options.key?(:sleep)
|
351
|
-
@sleep = options[:sleep]
|
352
|
-
end
|
353
|
-
|
354
|
-
if options.key?(:gc_flush_interval)
|
355
|
-
@gc_flush_interval = options[:gc_flush_interval]
|
356
|
-
end
|
357
|
-
|
358
|
-
if options.key?(:queue_poll_wait)
|
359
|
-
@queue_poll_wait = options[:queue_poll_wait]
|
360
|
-
end
|
361
|
-
|
362
|
-
EventQ.logger.info("[#{self.class}] - Configuring. Thread Count: #{@thread_count} | Interval Sleep: #{@sleep} | GC Flush Interval: #{@gc_flush_interval} | Queue Poll Wait: #{@queue_poll_wait}.")
|
363
|
-
|
364
|
-
return true
|
365
|
-
|
366
|
-
end
|
367
|
-
|
368
|
-
end
|
369
|
-
end
|
370
|
-
end
|
@@ -1,20 +0,0 @@
|
|
1
|
-
module EventQ
|
2
|
-
module SerializationProviders
|
3
|
-
module JRuby
|
4
|
-
module Oj
|
5
|
-
class ArrayWriter < AttributeWriter
|
6
|
-
def valid?(obj)
|
7
|
-
obj.is_a?(Array)
|
8
|
-
end
|
9
|
-
def exec(obj)
|
10
|
-
array = []
|
11
|
-
obj.each do |a|
|
12
|
-
array << AttributeWriter.exec(a)
|
13
|
-
end
|
14
|
-
array
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
@@ -1,24 +0,0 @@
|
|
1
|
-
module EventQ
|
2
|
-
module SerializationProviders
|
3
|
-
module JRuby
|
4
|
-
module Oj
|
5
|
-
class AttributeWriter
|
6
|
-
|
7
|
-
def self.exec(obj)
|
8
|
-
aw = descendants.detect { |a| a.new.valid?(obj) } || ClassWriter
|
9
|
-
aw.new.exec(obj)
|
10
|
-
end
|
11
|
-
|
12
|
-
def self.descendants
|
13
|
-
descendants = []
|
14
|
-
ObjectSpace.each_object(singleton_class) do |k|
|
15
|
-
next if k.singleton_class?
|
16
|
-
descendants.unshift k unless k == self
|
17
|
-
end
|
18
|
-
descendants
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|
@@ -1,20 +0,0 @@
|
|
1
|
-
module EventQ
|
2
|
-
module SerializationProviders
|
3
|
-
module JRuby
|
4
|
-
module Oj
|
5
|
-
class ClassWriter < AttributeWriter
|
6
|
-
def valid?(obj)
|
7
|
-
false
|
8
|
-
end
|
9
|
-
def exec(obj)
|
10
|
-
hash = { '^o': obj.class }
|
11
|
-
obj.instance_variables.each do |key|
|
12
|
-
hash[key[1..-1]] = AttributeWriter.exec(obj.instance_variable_get(key))
|
13
|
-
end
|
14
|
-
hash
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
@@ -1,33 +0,0 @@
|
|
1
|
-
module EventQ
|
2
|
-
module SerializationProviders
|
3
|
-
module JRuby
|
4
|
-
module Oj
|
5
|
-
class DateTimeWriter < AttributeWriter
|
6
|
-
def valid?(obj)
|
7
|
-
obj.is_a?(DateTime)
|
8
|
-
end
|
9
|
-
def exec(obj)
|
10
|
-
seconds = obj.strftime('%S%N')
|
11
|
-
d = 1_000_000_000
|
12
|
-
if seconds.start_with?('0')
|
13
|
-
seconds[0] = ''
|
14
|
-
d = 100_000_000
|
15
|
-
end
|
16
|
-
|
17
|
-
{
|
18
|
-
'^O': 'DateTime',
|
19
|
-
year: obj.year,
|
20
|
-
month: obj.month,
|
21
|
-
day: obj.day,
|
22
|
-
hour: obj.hour,
|
23
|
-
min: obj.min,
|
24
|
-
sec: RationalWriter.new.exec(Rational(Integer(seconds), d)),
|
25
|
-
offset: RationalWriter.new.exec(obj.offset),
|
26
|
-
start: obj.start
|
27
|
-
}
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|
@@ -1,22 +0,0 @@
|
|
1
|
-
module EventQ
|
2
|
-
module SerializationProviders
|
3
|
-
module JRuby
|
4
|
-
module Oj
|
5
|
-
class DateWriter < AttributeWriter
|
6
|
-
def valid?(obj)
|
7
|
-
obj.is_a?(Date) && !obj.is_a?(DateTime)
|
8
|
-
end
|
9
|
-
def exec(obj)
|
10
|
-
{
|
11
|
-
'^O': 'Date',
|
12
|
-
year: obj.year,
|
13
|
-
month: obj.month,
|
14
|
-
day: obj.day,
|
15
|
-
start: obj.start
|
16
|
-
}
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
@@ -1,18 +0,0 @@
|
|
1
|
-
module EventQ
|
2
|
-
module SerializationProviders
|
3
|
-
module JRuby
|
4
|
-
module Oj
|
5
|
-
class HashWriter < AttributeWriter
|
6
|
-
def valid?(obj)
|
7
|
-
obj.is_a?(Hash)
|
8
|
-
end
|
9
|
-
def exec(obj)
|
10
|
-
obj.each do |key, value|
|
11
|
-
obj[key] = AttributeWriter.exec(value)
|
12
|
-
end
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|