aws-sdk-rails 3.9.1 → 3.10.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: 1491284a363942f9a0d4fe8712449caf2989869377fdb283632bec9c11b71b0b
4
- data.tar.gz: c1f65e37b61266b80a20c06c21a39f84f7283ade2b9a590e5b80d3963ada71c7
3
+ metadata.gz: 34ec24104d9eb230956480f01ab20a9eefc670510727104c4b7ee930f31b281c
4
+ data.tar.gz: 8a60649a724d96aac5c927ad8090b3d942d860f3d6b755a3815cdd65777d46fa
5
5
  SHA512:
6
- metadata.gz: 456ead7237daf5d83f55f4858f11d40a3d213a3bd8f8ded27c56be10e94e7aba6708a2adad8739b324991f28d22b97e32b8272d073f8f0bc082d390abfff8267
7
- data.tar.gz: 97da8e92ec42c8404af945049feae80044aa2d6d1fed276eaf40bd50baa2b07826cfd201ed7eda00a92a9d1636749aaec0cc1adbc159a300c1d5b9690c86fc96
6
+ metadata.gz: 268c6e207ee1736ba3dad6450c7ccf0461ae0bd5dc55eb1bbae755a5ac5853f3edbef91fb140447c1a62327ca73a91bf534e39f908e51a8e771eab859a9fa389
7
+ data.tar.gz: 3033033fa8121807e2306c57368e29095a746741df12eec4f61b0daa7e388cafb1bf93eb35be67664205c3d0040cdb26151d729bb36b11fed2143547b2205780
data/VERSION CHANGED
@@ -1 +1 @@
1
- 3.9.1
1
+ 3.10.0
@@ -0,0 +1,78 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ActiveJob
4
+ module QueueAdapters
5
+ class AmazonSqsAdapter
6
+ # == build request parameter of Aws::SQS::Client
7
+ class Params
8
+ class << self
9
+ def assured_delay_seconds(timestamp)
10
+ delay = (timestamp - Time.now.to_f).floor
11
+ delay = 0 if delay.negative?
12
+ raise ArgumentError, 'Unable to queue a job with a delay great than 15 minutes' if delay > 15.minutes
13
+
14
+ delay
15
+ end
16
+ end
17
+
18
+ def initialize(job, body)
19
+ @job = job
20
+ @body = body || job.serialize
21
+ end
22
+
23
+ def queue_url
24
+ @queue_url ||= Aws::Rails::SqsActiveJob.config.queue_url_for(@job.queue_name)
25
+ end
26
+
27
+ def entry
28
+ if Aws::Rails::SqsActiveJob.fifo?(queue_url)
29
+ default_entry.merge(options_for_fifo)
30
+ else
31
+ default_entry
32
+ end
33
+ end
34
+
35
+ private
36
+
37
+ def default_entry
38
+ {
39
+ message_body: Aws::Json.dump(@body),
40
+ message_attributes: message_attributes
41
+ }
42
+ end
43
+
44
+ def message_attributes
45
+ {
46
+ 'aws_sqs_active_job_class' => {
47
+ string_value: @job.class.to_s,
48
+ data_type: 'String'
49
+ },
50
+ 'aws_sqs_active_job_version' => {
51
+ string_value: Aws::Rails::VERSION,
52
+ data_type: 'String'
53
+ }
54
+ }
55
+ end
56
+
57
+ def options_for_fifo
58
+ options = {}
59
+ options[:message_deduplication_id] =
60
+ Digest::SHA256.hexdigest(Aws::Json.dump(deduplication_body))
61
+
62
+ message_group_id = @job.message_group_id if @job.respond_to?(:message_group_id)
63
+ message_group_id ||= Aws::Rails::SqsActiveJob.config.message_group_id
64
+
65
+ options[:message_group_id] = message_group_id
66
+ options
67
+ end
68
+
69
+ def deduplication_body
70
+ ex_dedup_keys = @job.excluded_deduplication_keys if @job.respond_to?(:excluded_deduplication_keys)
71
+ ex_dedup_keys ||= Aws::Rails::SqsActiveJob.config.excluded_deduplication_keys
72
+
73
+ @body.except(*ex_dedup_keys)
74
+ end
75
+ end
76
+ end
77
+ end
78
+ end
@@ -10,55 +10,44 @@ module ActiveJob
10
10
  end
11
11
 
12
12
  def enqueue_at(job, timestamp)
13
- delay = (timestamp - Time.now.to_f).floor
14
-
15
- delay = 0 if delay.negative?
16
- raise ArgumentError, 'Unable to queue a job with a delay great than 15 minutes' if delay > 15.minutes
17
-
13
+ delay = Params.assured_delay_seconds(timestamp)
18
14
  _enqueue(job, nil, delay_seconds: delay)
19
15
  end
20
16
 
17
+ def enqueue_all(jobs)
18
+ enqueued_count = 0
19
+ jobs.group_by(&:queue_name).each do |queue_name, same_queue_jobs|
20
+ queue_url = Aws::Rails::SqsActiveJob.config.queue_url_for(queue_name)
21
+ base_send_message_opts = { queue_url: queue_url }
22
+
23
+ same_queue_jobs.each_slice(10) do |chunk|
24
+ entries = chunk.map do |job|
25
+ entry = Params.new(job, nil).entry
26
+ entry[:id] = job.job_id
27
+ entry[:delay_seconds] = Params.assured_delay_seconds(job.scheduled_at) if job.scheduled_at
28
+ entry
29
+ end
30
+
31
+ send_message_opts = base_send_message_opts.deep_dup
32
+ send_message_opts[:entries] = entries
33
+
34
+ send_message_batch_result = Aws::Rails::SqsActiveJob.config.client.send_message_batch(send_message_opts)
35
+ enqueued_count += send_message_batch_result.successful.count
36
+ end
37
+ end
38
+ enqueued_count
39
+ end
40
+
21
41
  private
22
42
 
23
43
  def _enqueue(job, body = nil, send_message_opts = {})
24
44
  body ||= job.serialize
25
- queue_url = Aws::Rails::SqsActiveJob.config.queue_url_for(job.queue_name)
26
- send_message_opts[:queue_url] = queue_url
27
- send_message_opts[:message_body] = Aws::Json.dump(body)
28
- send_message_opts[:message_attributes] = message_attributes(job)
29
-
30
- if Aws::Rails::SqsActiveJob.fifo?(queue_url)
31
- send_message_opts[:message_deduplication_id] =
32
- Digest::SHA256.hexdigest(Aws::Json.dump(deduplication_body(job, body)))
33
-
34
- message_group_id = job.message_group_id if job.respond_to?(:message_group_id)
35
- message_group_id ||= Aws::Rails::SqsActiveJob.config.message_group_id
36
-
37
- send_message_opts[:message_group_id] = message_group_id
38
- end
45
+ params = Params.new(job, body)
46
+ send_message_opts = send_message_opts.merge(params.entry)
47
+ send_message_opts[:queue_url] = params.queue_url
39
48
 
40
49
  Aws::Rails::SqsActiveJob.config.client.send_message(send_message_opts)
41
50
  end
42
-
43
- def message_attributes(job)
44
- {
45
- 'aws_sqs_active_job_class' => {
46
- string_value: job.class.to_s,
47
- data_type: 'String'
48
- },
49
- 'aws_sqs_active_job_version' => {
50
- string_value: Aws::Rails::VERSION,
51
- data_type: 'String'
52
- }
53
- }
54
- end
55
-
56
- def deduplication_body(job, body)
57
- ex_dedup_keys = job.excluded_deduplication_keys if job.respond_to?(:excluded_deduplication_keys)
58
- ex_dedup_keys ||= Aws::Rails::SqsActiveJob.config.excluded_deduplication_keys
59
-
60
- body.except(*ex_dedup_keys)
61
- end
62
51
  end
63
52
 
64
53
  # create an alias to allow `:amazon` to be used as the adapter name
@@ -126,7 +126,7 @@ module Aws
126
126
  def to_h
127
127
  h = {}
128
128
  instance_variables.each do |v|
129
- v_sym = v.to_s.gsub('@', '').to_sym
129
+ v_sym = v.to_s.delete('@').to_sym
130
130
  val = instance_variable_get(v)
131
131
  h[v_sym] = val
132
132
  end
data/lib/aws-sdk-rails.rb CHANGED
@@ -13,6 +13,7 @@ require_relative 'aws/rails/middleware/ebs_sqs_active_job_middleware'
13
13
 
14
14
  require_relative 'action_dispatch/session/dynamodb_store'
15
15
  require_relative 'active_job/queue_adapters/amazon_sqs_adapter'
16
+ require_relative 'active_job/queue_adapters/amazon_sqs_adapter/params'
16
17
  require_relative 'active_job/queue_adapters/amazon_sqs_async_adapter'
17
18
 
18
19
  require_relative 'generators/aws_record/base'
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.9.1
4
+ version: 3.10.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-12-19 00:00:00.000000000 Z
11
+ date: 2024-01-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: aws-record
@@ -152,6 +152,7 @@ files:
152
152
  - bin/aws_sqs_active_job
153
153
  - lib/action_dispatch/session/dynamodb_store.rb
154
154
  - lib/active_job/queue_adapters/amazon_sqs_adapter.rb
155
+ - lib/active_job/queue_adapters/amazon_sqs_adapter/params.rb
155
156
  - lib/active_job/queue_adapters/amazon_sqs_async_adapter.rb
156
157
  - lib/aws-sdk-rails.rb
157
158
  - lib/aws/rails/middleware/ebs_sqs_active_job_middleware.rb