aws-sdk-rails 3.4.0 → 3.5.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b252fc5ed5514c1ab48750fc65acde4008f1f6a8b685bae42903708f7b987a14
4
- data.tar.gz: da794888829a46dfeec19350997e753b9858bf07a0668ef603594d9db46bdf9a
3
+ metadata.gz: 06b6734cbbe89bfbec53e688f583d78fb1a1fed48420c0a6b279d0025c8a65d3
4
+ data.tar.gz: 6a84d18c8fbb5807bb88e1b3c803ed94a72bb6287abc244341dfb1e05a595923
5
5
  SHA512:
6
- metadata.gz: 5c5a5f74b8faab027f2d8b3b64e32a4feb2e85c29207d051a66e93424b6b71d8dbdf0dd80ba1baac1b9be66489759c8efba1860fdba7d41990fbd8279d173b08
7
- data.tar.gz: 227f06499dbd9a1705eae1ffb00777502cbfa3f512c8e07b1a037d5b04a35afcc651487518ea582e646cf6060682112a85d8baf59e6a9d543eb7beb16c8e3fa7
6
+ metadata.gz: 339b7acd4cdc666589ec5921ac583b1b8ed17101fedf6637af957ede0863b0aebe025333ddbb8fdb1fe9a491d2f82f76b7cde81d62ad1eab6c58ae34605c8ecf
7
+ data.tar.gz: c5d8b881c1f5a9521800bc89dd491266088a03dd98845590e5d498e22538baee8f14a014048a3155adcc411a5ded72bc35e02f456097f1d838a4e3cbff905e02
data/VERSION CHANGED
@@ -1 +1 @@
1
- 3.4.0
1
+ 3.5.0
@@ -11,7 +11,7 @@ module ActiveJob
11
11
  _enqueue(job)
12
12
  end
13
13
 
14
- def enqueue_at(job, timestamp)
14
+ def enqueue_at(job, timestamp, opts={})
15
15
  delay = (timestamp - Time.now.to_f).floor
16
16
  raise ArgumentError, 'Unable to queue a job with a delay great than 15 minutes' if delay > 15.minutes
17
17
  _enqueue(job, delay_seconds: delay)
@@ -25,6 +25,18 @@ module ActiveJob
25
25
  send_message_opts[:queue_url] = queue_url
26
26
  send_message_opts[:message_body] = Aws::Json.dump(body)
27
27
  send_message_opts[:message_attributes] = message_attributes(job)
28
+
29
+ if Aws::Rails::SqsActiveJob.fifo?(queue_url)
30
+ # job_id is unique per initialization of job
31
+ # Remove it from message dup id to ensure run-once behavior
32
+ # with ActiveJob retries
33
+ send_message_opts[:message_deduplication_id] =
34
+ Digest::SHA256.hexdigest(
35
+ Aws::Json.dump(body.except('job_id'))
36
+ )
37
+
38
+ send_message_opts[:message_group_id] = Aws::Rails::SqsActiveJob.config.message_group_id
39
+ end
28
40
  Aws::Rails::SqsActiveJob.config.client.send_message(send_message_opts)
29
41
  end
30
42
 
@@ -19,12 +19,18 @@ module ActiveJob
19
19
  private
20
20
 
21
21
  def _enqueue(job, send_message_opts = {})
22
- Concurrent::Promise
23
- .execute { super(job, send_message_opts) }
24
- .on_error do |e|
25
- Rails.logger.error "Failed to queue job #{job}. Reason: #{e}"
26
- error_handler = Aws::Rails::SqsActiveJob.config.async_queue_error_handler
27
- error_handler.call(e, job, send_message_opts) if error_handler
22
+ # FIFO jobs must be queued in order, so do not queue async
23
+ queue_url = Aws::Rails::SqsActiveJob.config.queue_url_for(job.queue_name)
24
+ if Aws::Rails::SqsActiveJob.fifo?(queue_url)
25
+ super(job, send_message_opts)
26
+ else
27
+ Concurrent::Promise
28
+ .execute { super(job, send_message_opts) }
29
+ .on_error do |e|
30
+ Rails.logger.error "Failed to queue job #{job}. Reason: #{e}"
31
+ error_handler = Aws::Rails::SqsActiveJob.config.async_queue_error_handler
32
+ error_handler.call(e, job, send_message_opts) if error_handler
33
+ end
28
34
  end
29
35
  end
30
36
  end
@@ -14,6 +14,10 @@ module Aws
14
14
  yield(config)
15
15
  end
16
16
 
17
+ def self.fifo?(queue_url)
18
+ queue_url.ends_with? '.fifo'
19
+ end
20
+
17
21
  # Configuration for AWS SQS ActiveJob.
18
22
  # Use +Aws::Rails::SqsActiveJob.config+ to access the singleton config instance.
19
23
  class Configuration
@@ -25,12 +29,14 @@ module Aws
25
29
  visibility_timeout: 120,
26
30
  shutdown_timeout: 15,
27
31
  queues: {},
28
- logger: ::Rails.logger
32
+ logger: ::Rails.logger,
33
+ message_group_id: 'SqsActiveJobGroup'
29
34
  }
30
35
 
31
36
  # @api private
32
37
  attr_accessor :queues, :max_messages, :visibility_timeout,
33
- :shutdown_timeout, :client, :logger, :async_queue_error_handler
38
+ :shutdown_timeout, :client, :logger,
39
+ :async_queue_error_handler, :message_group_id
34
40
 
35
41
  # Don't use this method directly: Confugration is a singleton class, use
36
42
  # +Aws::Rails::SqsActiveJob.config+ to access the singleton config.
@@ -63,6 +69,11 @@ module Aws
63
69
  # Override file to load configuration from. If not specified will
64
70
  # attempt to load from config/aws_sqs_active_job.yml.
65
71
  #
72
+ # @option options [String] :message_group_id (SqsActiveJobGroup)
73
+ # The message_group_id to use for queueing messages on a fifo queues.
74
+ # Applies only to jobs queued on FIFO queues.
75
+ # See the (SQS FIFO Documentation)[https://docs.aws.amazon.com/AWSSimpleQueueService/latest/SQSDeveloperGuide/FIFO-queues.html]
76
+ #
66
77
  # @option options [Callable] :async_queue_error_handler An error handler
67
78
  # to be called when the async active job adapter experiances an error
68
79
  # queueing a job. Only applies when
@@ -69,12 +69,22 @@ module Aws
69
69
  @logger.info "Polling on: #{@options[:queue]} => #{queue_url}"
70
70
  client = Aws::Rails::SqsActiveJob.config.client
71
71
  @poller = Aws::SQS::QueuePoller.new(queue_url, client: client)
72
- single_message = @options[:max_messages] == 1
73
72
  poller_options = {
74
73
  skip_delete: true,
75
74
  max_number_of_messages: @options[:max_messages],
76
75
  visibility_timeout: @options[:visibility_timeout]
77
76
  }
77
+ # Limit max_number_of_messages for FIFO queues to 1
78
+ # this ensures jobs with the same message_group_id are processed
79
+ # in order
80
+ # Jobs with different message_group_id will be processed in
81
+ # parallel and may be out of order.
82
+ if Aws::Rails::SqsActiveJob.fifo?(queue_url)
83
+ poller_options[:max_number_of_messages] = 1
84
+ end
85
+
86
+ single_message = poller_options[:max_number_of_messages] == 1
87
+
78
88
  @poller.poll(poller_options) do |msgs|
79
89
  msgs = [msgs] if single_message
80
90
  @logger.info "Processing batch of #{msgs.length} messages"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: aws-sdk-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.4.0
4
+ version: 3.5.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: 2020-12-07 00:00:00.000000000 Z
11
+ date: 2021-01-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: aws-record