aws-sdk-sqs 1.63.0 → 1.65.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +10 -0
- data/VERSION +1 -1
- data/lib/aws-sdk-sqs/client.rb +1 -1
- data/lib/aws-sdk-sqs/queue_poller.rb +65 -35
- data/lib/aws-sdk-sqs.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: deb95ba88a1099fdc9be73f1cdcc07f050abcb43d14f3b12d7ef4e0eeba718a3
|
4
|
+
data.tar.gz: a55887d771d042ad936392d196a251e9a41a4635dc0b54ff5ac5f11baf749ada
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1fee7c9e83c30cc4cdc66d2a73edb2e23cfa418b3ad7ba500cbc690eb507532c03085efcb224d3c0ffe75c1a6fc534c900b52bb2c7942127e2564919c175fd13
|
7
|
+
data.tar.gz: d4cac974b7077791b7ea7cfd3f72b240d7eb50c7b3c323ac545279f75bd265aa1bdeb05fdc1db164709c9e91701787657b7cb261f250df9951c024e2d0e98969
|
data/CHANGELOG.md
CHANGED
@@ -1,6 +1,16 @@
|
|
1
1
|
Unreleased Changes
|
2
2
|
------------------
|
3
3
|
|
4
|
+
1.65.0 (2023-10-31)
|
5
|
+
------------------
|
6
|
+
|
7
|
+
* Feature - Update `QueuePoller` to allow for the definition of an `after_empty_receive` callback which is triggered when a polling request returns no records.
|
8
|
+
|
9
|
+
1.64.0 (2023-10-02)
|
10
|
+
------------------
|
11
|
+
|
12
|
+
* Feature - Update QueuePoller to handle duplicate messages before yielding. Fixes bug in (#2913).
|
13
|
+
|
4
14
|
1.63.0 (2023-09-27)
|
5
15
|
------------------
|
6
16
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.
|
1
|
+
1.65.0
|
data/lib/aws-sdk-sqs/client.rb
CHANGED
@@ -4,7 +4,6 @@ require 'set'
|
|
4
4
|
|
5
5
|
module Aws
|
6
6
|
module SQS
|
7
|
-
|
8
7
|
# A utility class for long polling messages in a loop. **Messages are
|
9
8
|
# automatically deleted from the queue at the end of the given block.**
|
10
9
|
#
|
@@ -181,6 +180,16 @@ module Aws
|
|
181
180
|
# end
|
182
181
|
# ```
|
183
182
|
#
|
183
|
+
# * Configure an {#after_empty_receive} callback.
|
184
|
+
#
|
185
|
+
# ```
|
186
|
+
# poller.after_empty_receive do |stats|
|
187
|
+
# logger.info("requests: #{stats.request_count}")
|
188
|
+
# logger.info("messages: #{stats.received_message_count}")
|
189
|
+
# logger.info("last-timestamp: #{stats.last_message_received_at}")
|
190
|
+
# end
|
191
|
+
# ```
|
192
|
+
#
|
184
193
|
# * Accept a 2nd argument in the poll block, for example:
|
185
194
|
#
|
186
195
|
# ```
|
@@ -203,7 +212,6 @@ module Aws
|
|
203
212
|
# ```
|
204
213
|
#
|
205
214
|
class QueuePoller
|
206
|
-
|
207
215
|
# @param [String] queue_url
|
208
216
|
# @option options [Client] :client
|
209
217
|
# @option (see #poll)
|
@@ -258,6 +266,21 @@ module Aws
|
|
258
266
|
@default_config = @default_config.with(before_request: block) if block_given?
|
259
267
|
end
|
260
268
|
|
269
|
+
# Registers a callback that is invoked when the poll requests returns with no messages.
|
270
|
+
# This callback is invoked after the idle timeout is checked.
|
271
|
+
#
|
272
|
+
# poller.after_empty_receive do |stats|
|
273
|
+
# # Handle empty receive
|
274
|
+
# end
|
275
|
+
#
|
276
|
+
# @yieldparam [PollerStats] stats An object that tracks a few
|
277
|
+
# client-side statistics about the queue polling.
|
278
|
+
#
|
279
|
+
# @return [void]
|
280
|
+
def after_empty_receive(&block)
|
281
|
+
@default_config = @default_config.with(after_empty_receive: block) if block_given?
|
282
|
+
end
|
283
|
+
|
261
284
|
# Polls the queue, yielded a message, or an array of messages.
|
262
285
|
# Messages are automatically deleted from the queue at the
|
263
286
|
# end of the given block. See the class documentation on
|
@@ -333,7 +356,8 @@ module Aws
|
|
333
356
|
loop do
|
334
357
|
messages = get_messages(config, stats)
|
335
358
|
if messages.empty?
|
336
|
-
check_idle_timeout(config, stats
|
359
|
+
check_idle_timeout(config, stats)
|
360
|
+
config.after_empty_receive&.call(stats)
|
337
361
|
else
|
338
362
|
process_messages(config, stats, messages, &block)
|
339
363
|
end
|
@@ -348,21 +372,21 @@ module Aws
|
|
348
372
|
# `#receipt_handle`.
|
349
373
|
# @param [Integer] seconds
|
350
374
|
def change_message_visibility_timeout(message, seconds)
|
351
|
-
@client.change_message_visibility(
|
375
|
+
@client.change_message_visibility(
|
352
376
|
queue_url: @queue_url,
|
353
377
|
receipt_handle: message.receipt_handle,
|
354
|
-
visibility_timeout: seconds
|
355
|
-
|
378
|
+
visibility_timeout: seconds
|
379
|
+
)
|
356
380
|
end
|
357
381
|
|
358
382
|
# @note This method should be called from inside a {#poll} block.
|
359
383
|
# @param [#receipt_handle] message An object that responds to
|
360
384
|
# `#receipt_handle`.
|
361
385
|
def delete_message(message)
|
362
|
-
@client.delete_message(
|
386
|
+
@client.delete_message(
|
363
387
|
queue_url: @queue_url,
|
364
|
-
receipt_handle: message.receipt_handle
|
365
|
-
|
388
|
+
receipt_handle: message.receipt_handle
|
389
|
+
)
|
366
390
|
end
|
367
391
|
|
368
392
|
# @note This method should be called from inside a {#poll} block.
|
@@ -372,16 +396,16 @@ module Aws
|
|
372
396
|
def delete_messages(messages)
|
373
397
|
@client.delete_message_batch(
|
374
398
|
queue_url: @queue_url,
|
375
|
-
entries: messages.map
|
399
|
+
entries: messages.map do |msg|
|
376
400
|
{ id: msg.message_id, receipt_handle: msg.receipt_handle }
|
377
|
-
|
401
|
+
end
|
378
402
|
)
|
379
403
|
end
|
380
404
|
|
381
405
|
private
|
382
406
|
|
383
407
|
def get_messages(config, stats)
|
384
|
-
config.before_request
|
408
|
+
config.before_request&.call(stats)
|
385
409
|
messages = send_request(config).messages
|
386
410
|
stats.request_count += 1
|
387
411
|
messages
|
@@ -392,17 +416,22 @@ module Aws
|
|
392
416
|
@client.receive_message(params)
|
393
417
|
end
|
394
418
|
|
395
|
-
def check_idle_timeout(config, stats
|
396
|
-
|
397
|
-
|
398
|
-
|
399
|
-
|
400
|
-
|
419
|
+
def check_idle_timeout(config, stats)
|
420
|
+
return unless config.idle_timeout
|
421
|
+
|
422
|
+
since = stats.last_message_received_at || stats.polling_started_at
|
423
|
+
idle_time = Time.now - since
|
424
|
+
throw :stop_polling if idle_time > config.idle_timeout
|
401
425
|
end
|
402
426
|
|
403
427
|
def process_messages(config, stats, messages, &block)
|
404
428
|
stats.received_message_count += messages.count
|
405
429
|
stats.last_message_received_at = Time.now
|
430
|
+
|
431
|
+
# duplicated messages will have a different receipt handle
|
432
|
+
# so we need to provide the most recent receipt to
|
433
|
+
# delete a batch - thus, filtering below by message_id
|
434
|
+
messages = messages.reverse.uniq(&:message_id).reverse!
|
406
435
|
catch(:skip_delete) do
|
407
436
|
yield_messages(config, messages, stats, &block)
|
408
437
|
delete_messages(messages) unless config.skip_delete
|
@@ -421,7 +450,6 @@ module Aws
|
|
421
450
|
|
422
451
|
# Statistics tracked client-side by the {QueuePoller}.
|
423
452
|
class PollerStats
|
424
|
-
|
425
453
|
def initialize
|
426
454
|
@request_count = 0
|
427
455
|
@received_message_count = 0
|
@@ -444,27 +472,26 @@ module Aws
|
|
444
472
|
|
445
473
|
# @return [Time,nil]
|
446
474
|
attr_accessor :polling_stopped_at
|
447
|
-
|
448
475
|
end
|
449
476
|
|
450
477
|
# A read-only set of configuration used by the QueuePoller.
|
451
478
|
class PollerConfig
|
452
|
-
|
453
479
|
# @api private
|
454
|
-
CONFIG_OPTIONS = Set.new
|
455
|
-
|
456
|
-
|
457
|
-
|
458
|
-
|
480
|
+
CONFIG_OPTIONS = Set.new %i[
|
481
|
+
idle_timeout
|
482
|
+
skip_delete
|
483
|
+
before_request
|
484
|
+
after_empty_receive
|
485
|
+
]
|
459
486
|
|
460
487
|
# @api private
|
461
|
-
PARAM_OPTIONS = Set.new
|
462
|
-
|
463
|
-
|
464
|
-
|
465
|
-
|
466
|
-
|
467
|
-
]
|
488
|
+
PARAM_OPTIONS = Set.new %i[
|
489
|
+
wait_time_seconds
|
490
|
+
max_number_of_messages
|
491
|
+
visibility_timeout
|
492
|
+
attribute_names
|
493
|
+
message_attribute_names
|
494
|
+
]
|
468
495
|
|
469
496
|
# @return [Integer,nil]
|
470
497
|
attr_reader :idle_timeout
|
@@ -475,6 +502,9 @@ module Aws
|
|
475
502
|
# @return [Proc,nil]
|
476
503
|
attr_reader :before_request
|
477
504
|
|
505
|
+
# @return [Proc,nil]
|
506
|
+
attr_reader :after_empty_receive
|
507
|
+
|
478
508
|
# @return [Hash]
|
479
509
|
attr_reader :request_params
|
480
510
|
|
@@ -482,12 +512,13 @@ module Aws
|
|
482
512
|
@idle_timeout = nil
|
483
513
|
@skip_delete = false
|
484
514
|
@before_request = nil
|
515
|
+
@after_empty_receive = nil
|
485
516
|
@request_params = {
|
486
517
|
wait_time_seconds: 20,
|
487
518
|
max_number_of_messages: 1,
|
488
519
|
visibility_timeout: nil,
|
489
520
|
attribute_names: ['All'],
|
490
|
-
message_attribute_names: ['All']
|
521
|
+
message_attribute_names: ['All']
|
491
522
|
}
|
492
523
|
options.each do |opt_name, value|
|
493
524
|
if CONFIG_OPTIONS.include?(opt_name)
|
@@ -522,7 +553,6 @@ module Aws
|
|
522
553
|
PARAM_OPTIONS.each { |key| hash[key] = @request_params[key] }
|
523
554
|
hash
|
524
555
|
end
|
525
|
-
|
526
556
|
end
|
527
557
|
end
|
528
558
|
end
|
data/lib/aws-sdk-sqs.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: aws-sdk-sqs
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.65.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Amazon Web Services
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-
|
11
|
+
date: 2023-10-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: aws-sdk-core
|