aws-sdk-rails 3.9.0 → 3.10.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/VERSION +1 -1
- data/lib/active_job/queue_adapters/amazon_sqs_adapter/params.rb +78 -0
- data/lib/active_job/queue_adapters/amazon_sqs_adapter.rb +28 -37
- data/lib/aws/rails/sqs_active_job/configuration.rb +1 -1
- data/lib/aws-sdk-rails.rb +1 -0
- data/lib/generators/aws_record/base.rb +1 -1
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 34ec24104d9eb230956480f01ab20a9eefc670510727104c4b7ee930f31b281c
|
4
|
+
data.tar.gz: 8a60649a724d96aac5c927ad8090b3d942d860f3d6b755a3815cdd65777d46fa
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 268c6e207ee1736ba3dad6450c7ccf0461ae0bd5dc55eb1bbae755a5ac5853f3edbef91fb140447c1a62327ca73a91bf534e39f908e51a8e771eab859a9fa389
|
7
|
+
data.tar.gz: 3033033fa8121807e2306c57368e29095a746741df12eec4f61b0daa7e388cafb1bf93eb35be67664205c3d0040cdb26151d729bb36b11fed2143547b2205780
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
3.
|
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,53 +10,44 @@ module ActiveJob
|
|
10
10
|
end
|
11
11
|
|
12
12
|
def enqueue_at(job, timestamp)
|
13
|
-
delay = (timestamp
|
14
|
-
raise ArgumentError, 'Unable to queue a job with a delay great than 15 minutes' if delay > 15.minutes
|
15
|
-
|
13
|
+
delay = Params.assured_delay_seconds(timestamp)
|
16
14
|
_enqueue(job, nil, delay_seconds: delay)
|
17
15
|
end
|
18
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
|
+
|
19
41
|
private
|
20
42
|
|
21
43
|
def _enqueue(job, body = nil, send_message_opts = {})
|
22
44
|
body ||= job.serialize
|
23
|
-
|
24
|
-
send_message_opts
|
25
|
-
send_message_opts[:
|
26
|
-
send_message_opts[:message_attributes] = message_attributes(job)
|
27
|
-
|
28
|
-
if Aws::Rails::SqsActiveJob.fifo?(queue_url)
|
29
|
-
send_message_opts[:message_deduplication_id] =
|
30
|
-
Digest::SHA256.hexdigest(Aws::Json.dump(deduplication_body(job, body)))
|
31
|
-
|
32
|
-
message_group_id = job.message_group_id if job.respond_to?(:message_group_id)
|
33
|
-
message_group_id ||= Aws::Rails::SqsActiveJob.config.message_group_id
|
34
|
-
|
35
|
-
send_message_opts[:message_group_id] = message_group_id
|
36
|
-
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
|
37
48
|
|
38
49
|
Aws::Rails::SqsActiveJob.config.client.send_message(send_message_opts)
|
39
50
|
end
|
40
|
-
|
41
|
-
def message_attributes(job)
|
42
|
-
{
|
43
|
-
'aws_sqs_active_job_class' => {
|
44
|
-
string_value: job.class.to_s,
|
45
|
-
data_type: 'String'
|
46
|
-
},
|
47
|
-
'aws_sqs_active_job_version' => {
|
48
|
-
string_value: Aws::Rails::VERSION,
|
49
|
-
data_type: 'String'
|
50
|
-
}
|
51
|
-
}
|
52
|
-
end
|
53
|
-
|
54
|
-
def deduplication_body(job, body)
|
55
|
-
ex_dedup_keys = job.excluded_deduplication_keys if job.respond_to?(:excluded_deduplication_keys)
|
56
|
-
ex_dedup_keys ||= Aws::Rails::SqsActiveJob.config.excluded_deduplication_keys
|
57
|
-
|
58
|
-
body.except(*ex_dedup_keys)
|
59
|
-
end
|
60
51
|
end
|
61
52
|
|
62
53
|
# create an alias to allow `:amazon` to be used as the adapter name
|
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'
|
@@ -147,7 +147,7 @@ module AwsRecord
|
|
147
147
|
[idx.name, parse_rw_units(idx.name)]
|
148
148
|
end.to_h
|
149
149
|
|
150
|
-
options['table_config'].
|
150
|
+
options['table_config'].each_key do |config|
|
151
151
|
next if config == 'primary'
|
152
152
|
|
153
153
|
gsi = @gsis.select { |idx| idx.name == config }
|
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
|
+
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:
|
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
|
@@ -197,7 +198,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
197
198
|
- !ruby/object:Gem::Version
|
198
199
|
version: '0'
|
199
200
|
requirements: []
|
200
|
-
rubygems_version: 3.4.
|
201
|
+
rubygems_version: 3.4.22
|
201
202
|
signing_key:
|
202
203
|
specification_version: 4
|
203
204
|
summary: AWS SDK for Ruby on Rails Plugin
|