aws-sdk-rails 3.7.1 → 3.9.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/bin/aws_sqs_active_job +1 -0
- data/lib/action_dispatch/session/dynamodb_store.rb +4 -2
- data/lib/active_job/queue_adapters/amazon_sqs_adapter.rb +9 -6
- data/lib/active_job/queue_adapters/amazon_sqs_async_adapter.rb +0 -2
- data/lib/aws/rails/notifications.rb +1 -4
- data/lib/aws/rails/ses_mailer.rb +1 -0
- data/lib/aws/rails/sesv2_mailer.rb +1 -0
- data/lib/aws/rails/sqs_active_job/configuration.rb +35 -22
- data/lib/aws/rails/sqs_active_job/deduplication.rb +21 -0
- data/lib/aws/rails/sqs_active_job/executor.rb +11 -12
- data/lib/aws/rails/sqs_active_job/job_runner.rb +0 -1
- data/lib/aws/rails/sqs_active_job/lambda_handler.rb +1 -4
- data/lib/aws/rails/sqs_active_job/poller.rb +42 -29
- data/lib/aws-sdk-rails.rb +1 -0
- data/lib/generators/aws_record/base.rb +164 -164
- data/lib/generators/aws_record/generated_attribute.rb +50 -41
- data/lib/generators/aws_record/model/model_generator.rb +8 -4
- data/lib/generators/aws_record/secondary_index.rb +31 -25
- data/lib/generators/dynamo_db/session_store_migration/session_store_migration_generator.rb +2 -0
- data/lib/tasks/aws_record/migrate.rake +2 -0
- data/lib/tasks/dynamo_db/session_store.rake +2 -0
- metadata +34 -16
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 79de6d1c1c8319fd70a36949eebb7630630bbd9b8a566b6f473d51590e48af38
|
4
|
+
data.tar.gz: a7d383cfecc470333c998f61ca380330dac77dc13dc5d302a5ba6bb34f8e5a81
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 95e0b8f6e3e565b6aeba24955bdbacff0a280de8c7f8a976a75ebadfd28710fc47c34c4fc079d95bb7d2678f60c185ec158719864eee0f8935424d4adb99d2e1
|
7
|
+
data.tar.gz: 95c7da0d1ac045139de0e1b4f251b1a118cadfa62a4eef3bfe8925df0e914325f7523fb3009cc3bb433828d4ea916f0c1e12b919a689931773317492a6811156
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
3.
|
1
|
+
3.9.0
|
data/bin/aws_sqs_active_job
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'aws-sessionstore-dynamodb'
|
2
4
|
require 'action_dispatch/middleware/session/abstract_store'
|
3
5
|
|
@@ -19,7 +21,7 @@ module ActionDispatch
|
|
19
21
|
include SessionObject
|
20
22
|
|
21
23
|
def initialize(app, options = {})
|
22
|
-
options[:config_file] ||= config_file if
|
24
|
+
options[:config_file] ||= config_file if File.exist?(config_file)
|
23
25
|
options[:secret_key] ||= Rails.application.secret_key_base
|
24
26
|
super
|
25
27
|
end
|
@@ -28,7 +30,7 @@ module ActionDispatch
|
|
28
30
|
|
29
31
|
def config_file
|
30
32
|
file = Rails.root.join("config/dynamo_db_session_store/#{Rails.env}.yml")
|
31
|
-
file = Rails.root.join('config/dynamo_db_session_store.yml') unless
|
33
|
+
file = Rails.root.join('config/dynamo_db_session_store.yml') unless File.exist?(file)
|
32
34
|
file
|
33
35
|
end
|
34
36
|
end
|
@@ -4,9 +4,7 @@ require 'aws-sdk-sqs'
|
|
4
4
|
|
5
5
|
module ActiveJob
|
6
6
|
module QueueAdapters
|
7
|
-
|
8
7
|
class AmazonSqsAdapter
|
9
|
-
|
10
8
|
def enqueue(job)
|
11
9
|
_enqueue(job)
|
12
10
|
end
|
@@ -14,6 +12,7 @@ module ActiveJob
|
|
14
12
|
def enqueue_at(job, timestamp)
|
15
13
|
delay = (timestamp - Time.now.to_f).floor
|
16
14
|
raise ArgumentError, 'Unable to queue a job with a delay great than 15 minutes' if delay > 15.minutes
|
15
|
+
|
17
16
|
_enqueue(job, nil, delay_seconds: delay)
|
18
17
|
end
|
19
18
|
|
@@ -27,11 +26,8 @@ module ActiveJob
|
|
27
26
|
send_message_opts[:message_attributes] = message_attributes(job)
|
28
27
|
|
29
28
|
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
29
|
send_message_opts[:message_deduplication_id] =
|
34
|
-
Digest::SHA256.hexdigest(Aws::Json.dump(body
|
30
|
+
Digest::SHA256.hexdigest(Aws::Json.dump(deduplication_body(job, body)))
|
35
31
|
|
36
32
|
message_group_id = job.message_group_id if job.respond_to?(:message_group_id)
|
37
33
|
message_group_id ||= Aws::Rails::SqsActiveJob.config.message_group_id
|
@@ -54,6 +50,13 @@ module ActiveJob
|
|
54
50
|
}
|
55
51
|
}
|
56
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
|
57
60
|
end
|
58
61
|
|
59
62
|
# create an alias to allow `:amazon` to be used as the adapter name
|
@@ -5,7 +5,6 @@ require 'concurrent'
|
|
5
5
|
|
6
6
|
module ActiveJob
|
7
7
|
module QueueAdapters
|
8
|
-
|
9
8
|
# == Async adapter for Amazon SQS ActiveJob
|
10
9
|
#
|
11
10
|
# This adapter queues jobs asynchronously (ie non-blocking). Error handler can be configured
|
@@ -15,7 +14,6 @@ module ActiveJob
|
|
15
14
|
#
|
16
15
|
# config.active_job.queue_adapter = :amazon_sqs_async
|
17
16
|
class AmazonSqsAsyncAdapter < AmazonSqsAdapter
|
18
|
-
|
19
17
|
private
|
20
18
|
|
21
19
|
def _enqueue(job, body = nil, send_message_opts = {})
|
@@ -5,14 +5,12 @@ require 'active_support/notifications'
|
|
5
5
|
|
6
6
|
module Aws
|
7
7
|
module Rails
|
8
|
-
|
9
8
|
# Instruments client operation calls for ActiveSupport::Notifications
|
10
9
|
# Each client operation will produce an event with name:
|
11
10
|
# <operation>.<service>.aws
|
12
11
|
# @api private
|
13
12
|
class Notifications < Seahorse::Client::Plugin
|
14
|
-
|
15
|
-
def add_handlers(handlers, config)
|
13
|
+
def add_handlers(handlers, _config)
|
16
14
|
# This plugin needs to be first
|
17
15
|
# which means it is called first in the stack, to start recording time,
|
18
16
|
# and returns last
|
@@ -20,7 +18,6 @@ module Aws
|
|
20
18
|
end
|
21
19
|
|
22
20
|
class Handler < Seahorse::Client::Handler
|
23
|
-
|
24
21
|
def call(context)
|
25
22
|
event_name = "#{context.operation_name}.#{context.config.api.metadata['serviceId']}.aws"
|
26
23
|
ActiveSupport::Notifications.instrument(event_name, context: context) do
|
data/lib/aws/rails/ses_mailer.rb
CHANGED
@@ -20,6 +20,7 @@ module Aws
|
|
20
20
|
# [Aws::SES::Client.new](https://docs.aws.amazon.com/sdk-for-ruby/v3/api/Aws/SES/Client.html#initialize-instance_method).
|
21
21
|
def initialize(options = {})
|
22
22
|
@client = SES::Client.new(options)
|
23
|
+
@client.config.user_agent_frameworks << 'aws-sdk-rails'
|
23
24
|
end
|
24
25
|
|
25
26
|
# Rails expects this method to exist, and to handle a Mail::Message object
|
@@ -20,6 +20,7 @@ module Aws
|
|
20
20
|
# [Aws::SESV2::Client.new](https://docs.aws.amazon.com/sdk-for-ruby/v3/api/Aws/SESV2/Client.html#initialize-instance_method).
|
21
21
|
def initialize(options = {})
|
22
22
|
@client = SESV2::Client.new(options)
|
23
|
+
@client.config.user_agent_frameworks << 'aws-sdk-rails'
|
23
24
|
end
|
24
25
|
|
25
26
|
# Rails expects this method to exist, and to handle a Mail::Message object
|
@@ -3,7 +3,6 @@
|
|
3
3
|
module Aws
|
4
4
|
module Rails
|
5
5
|
module SqsActiveJob
|
6
|
-
|
7
6
|
# @return [Configuration] the (singleton) Configuration
|
8
7
|
def self.config
|
9
8
|
@config ||= Configuration.new
|
@@ -21,23 +20,25 @@ module Aws
|
|
21
20
|
# Configuration for AWS SQS ActiveJob.
|
22
21
|
# Use +Aws::Rails::SqsActiveJob.config+ to access the singleton config instance.
|
23
22
|
class Configuration
|
24
|
-
|
25
23
|
# Default configuration options
|
26
24
|
# @api private
|
27
25
|
DEFAULTS = {
|
28
|
-
max_messages:
|
26
|
+
max_messages: 10,
|
29
27
|
shutdown_timeout: 15,
|
30
28
|
queues: {},
|
31
29
|
logger: ::Rails.logger,
|
32
|
-
message_group_id: 'SqsActiveJobGroup'
|
33
|
-
|
30
|
+
message_group_id: 'SqsActiveJobGroup',
|
31
|
+
excluded_deduplication_keys: ['job_id']
|
32
|
+
}.freeze
|
34
33
|
|
35
34
|
# @api private
|
36
35
|
attr_accessor :queues, :max_messages, :visibility_timeout,
|
37
36
|
:shutdown_timeout, :client, :logger,
|
38
37
|
:async_queue_error_handler, :message_group_id
|
39
38
|
|
40
|
-
|
39
|
+
attr_reader :excluded_deduplication_keys
|
40
|
+
|
41
|
+
# Don't use this method directly: Configuration is a singleton class, use
|
41
42
|
# +Aws::Rails::SqsActiveJob.config+ to access the singleton config.
|
42
43
|
#
|
43
44
|
# @param [Hash] options
|
@@ -67,7 +68,7 @@ module Aws
|
|
67
68
|
# for the poller.
|
68
69
|
#
|
69
70
|
# @option options [String] :config_file
|
70
|
-
# Override file to load configuration from.
|
71
|
+
# Override file to load configuration from. If not specified will
|
71
72
|
# attempt to load from config/aws_sqs_active_job.yml.
|
72
73
|
#
|
73
74
|
# @option options [String] :message_group_id (SqsActiveJobGroup)
|
@@ -81,18 +82,31 @@ module Aws
|
|
81
82
|
# +active_job.queue_adapter = :amazon_sqs_async+. Called with:
|
82
83
|
# [error, job, job_options]
|
83
84
|
#
|
84
|
-
# @option options [SQS::Client] :client SQS Client to use.
|
85
|
+
# @option options [SQS::Client] :client SQS Client to use. A default
|
85
86
|
# client will be created if none is provided.
|
87
|
+
#
|
88
|
+
# @option options [Array] :excluded_deduplication_keys (['job_id'])
|
89
|
+
# The type of keys stored in the array should be String or Symbol.
|
90
|
+
# Using this option, job_id is implicitly added to the keys.
|
91
|
+
|
86
92
|
def initialize(options = {})
|
87
|
-
options[:config_file] ||= config_file if
|
93
|
+
options[:config_file] ||= config_file if File.exist?(config_file)
|
88
94
|
options = DEFAULTS
|
89
|
-
|
90
|
-
|
95
|
+
.merge(file_options(options))
|
96
|
+
.merge(options)
|
91
97
|
set_attributes(options)
|
92
98
|
end
|
93
99
|
|
100
|
+
def excluded_deduplication_keys=(keys)
|
101
|
+
@excluded_deduplication_keys = keys.map(&:to_s) | ['job_id']
|
102
|
+
end
|
103
|
+
|
94
104
|
def client
|
95
|
-
@client ||=
|
105
|
+
@client ||= begin
|
106
|
+
client = Aws::SQS::Client.new
|
107
|
+
client.config.user_agent_frameworks << 'aws-sdk-rails'
|
108
|
+
client
|
109
|
+
end
|
96
110
|
end
|
97
111
|
|
98
112
|
# Return the queue_url for a given job_queue name
|
@@ -111,9 +125,9 @@ module Aws
|
|
111
125
|
# @api private
|
112
126
|
def to_h
|
113
127
|
h = {}
|
114
|
-
|
128
|
+
instance_variables.each do |v|
|
115
129
|
v_sym = v.to_s.gsub('@', '').to_sym
|
116
|
-
val =
|
130
|
+
val = instance_variable_get(v)
|
117
131
|
h[v_sym] = val
|
118
132
|
end
|
119
133
|
h
|
@@ -123,8 +137,9 @@ module Aws
|
|
123
137
|
|
124
138
|
# Set accessible attributes after merged options.
|
125
139
|
def set_attributes(options)
|
126
|
-
options.
|
140
|
+
options.each_key do |opt_name|
|
127
141
|
instance_variable_set("@#{opt_name}", options[opt_name])
|
142
|
+
client.config.user_agent_frameworks << 'aws-sdk-rails' if opt_name == :client
|
128
143
|
end
|
129
144
|
end
|
130
145
|
|
@@ -139,7 +154,7 @@ module Aws
|
|
139
154
|
|
140
155
|
def config_file
|
141
156
|
file = ::Rails.root.join("config/aws_sqs_active_job/#{::Rails.env}.yml")
|
142
|
-
file = ::Rails.root.join('config/aws_sqs_active_job.yml') unless
|
157
|
+
file = ::Rails.root.join('config/aws_sqs_active_job.yml') unless File.exist?(file)
|
143
158
|
file
|
144
159
|
end
|
145
160
|
|
@@ -151,24 +166,22 @@ module Aws
|
|
151
166
|
|
152
167
|
# @return [String] Configuration path found in environment or YAML file.
|
153
168
|
def config_file_path(options)
|
154
|
-
options[:config_file] || ENV
|
155
|
-
end
|
156
|
-
|
157
|
-
def user_agent
|
158
|
-
"ft/aws-sdk-rails-activejob/#{Aws::Rails::VERSION}"
|
169
|
+
options[:config_file] || ENV.fetch('AWS_SQS_ACTIVE_JOB_CONFIG_FILE', nil)
|
159
170
|
end
|
160
171
|
|
161
172
|
def load_yaml(file_path)
|
162
|
-
require
|
173
|
+
require 'erb'
|
163
174
|
source = ERB.new(File.read(file_path)).result
|
164
175
|
|
165
176
|
# Avoid incompatible changes with Psych 4.0.0
|
166
177
|
# https://bugs.ruby-lang.org/issues/17866
|
178
|
+
# rubocop:disable Security/YAMLLoad
|
167
179
|
begin
|
168
180
|
YAML.load(source, aliases: true) || {}
|
169
181
|
rescue ArgumentError
|
170
182
|
YAML.load(source) || {}
|
171
183
|
end
|
184
|
+
# rubocop:enable Security/YAMLLoad
|
172
185
|
end
|
173
186
|
end
|
174
187
|
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Aws
|
4
|
+
module Rails
|
5
|
+
# SQS ActiveJob modules
|
6
|
+
module SqsActiveJob
|
7
|
+
extend ActiveSupport::Concern
|
8
|
+
|
9
|
+
included do
|
10
|
+
class_attribute :excluded_deduplication_keys
|
11
|
+
end
|
12
|
+
|
13
|
+
# class methods for SQS ActiveJob.
|
14
|
+
module ClassMethods
|
15
|
+
def deduplicate_without(*keys)
|
16
|
+
self.excluded_deduplication_keys = keys.map(&:to_s) | ['job_id']
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -7,18 +7,17 @@ module Aws
|
|
7
7
|
module SqsActiveJob
|
8
8
|
# CLI runner for polling for SQS ActiveJobs
|
9
9
|
class Executor
|
10
|
-
|
11
10
|
DEFAULTS = {
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
11
|
+
min_threads: 0,
|
12
|
+
max_threads: Concurrent.processor_count,
|
13
|
+
auto_terminate: true,
|
14
|
+
idletime: 60, # 1 minute
|
15
|
+
fallback_policy: :caller_runs # slow down the producer thread
|
17
16
|
}.freeze
|
18
17
|
|
19
18
|
def initialize(options = {})
|
20
19
|
@executor = Concurrent::ThreadPoolExecutor.new(DEFAULTS.merge(options))
|
21
|
-
@logger = options[:logger] || ActiveSupport::Logger.new(
|
20
|
+
@logger = options[:logger] || ActiveSupport::Logger.new($stdout)
|
22
21
|
end
|
23
22
|
|
24
23
|
# TODO: Consider catching the exception and sleeping instead of using :caller_runs
|
@@ -40,16 +39,16 @@ module Aws
|
|
40
39
|
end
|
41
40
|
end
|
42
41
|
|
43
|
-
def shutdown(timeout=nil)
|
42
|
+
def shutdown(timeout = nil)
|
44
43
|
@executor.shutdown
|
45
44
|
clean_shutdown = @executor.wait_for_termination(timeout)
|
46
45
|
if clean_shutdown
|
47
46
|
@logger.info 'Clean shutdown complete. All executing jobs finished.'
|
48
47
|
else
|
49
|
-
@logger.info "Timeout (#{timeout}) exceeded. Some jobs may not have"\
|
50
|
-
|
51
|
-
|
52
|
-
|
48
|
+
@logger.info "Timeout (#{timeout}) exceeded. Some jobs may not have " \
|
49
|
+
'finished cleanly. Unfinished jobs will not be removed from ' \
|
50
|
+
'the queue and can be ru-run once their visibility timeout ' \
|
51
|
+
'passes.'
|
53
52
|
end
|
54
53
|
end
|
55
54
|
end
|
@@ -5,7 +5,6 @@ require 'aws-sdk-sqs'
|
|
5
5
|
module Aws
|
6
6
|
module Rails
|
7
7
|
module SqsActiveJob
|
8
|
-
|
9
8
|
# A lambda event handler to run jobs from an SQS queue trigger
|
10
9
|
# Trigger the lambda from your SQS queue
|
11
10
|
# Configure the entrypoint to: +config/environment.Aws::Rails::SqsActiveJob.lambda_job_handler+
|
@@ -23,13 +22,11 @@ module Aws
|
|
23
22
|
"Processed #{event['Records'].length} jobs."
|
24
23
|
end
|
25
24
|
|
26
|
-
private
|
27
|
-
|
28
25
|
def self.to_sqs_msg(record)
|
29
26
|
msg = Aws::SQS::Types::Message.new(
|
30
27
|
body: record['body'],
|
31
28
|
md5_of_body: record['md5OfBody'],
|
32
|
-
message_attributes:
|
29
|
+
message_attributes: to_message_attributes(record),
|
33
30
|
message_id: record['messageId'],
|
34
31
|
receipt_handle: record['receiptHandle']
|
35
32
|
)
|
@@ -7,19 +7,17 @@ require 'concurrent'
|
|
7
7
|
module Aws
|
8
8
|
module Rails
|
9
9
|
module SqsActiveJob
|
10
|
-
|
11
|
-
class Interrupt < Exception; end
|
10
|
+
class Interrupt < StandardError; end
|
12
11
|
|
13
12
|
# CLI runner for polling for SQS ActiveJobs
|
14
13
|
# Use `aws_sqs_active_job --help` for detailed usage
|
15
14
|
class Poller
|
16
|
-
|
17
15
|
DEFAULT_OPTS = {
|
18
|
-
threads: 2*Concurrent.processor_count,
|
16
|
+
threads: 2 * Concurrent.processor_count,
|
19
17
|
max_messages: 10,
|
20
18
|
shutdown_timeout: 15,
|
21
19
|
backpressure: 10
|
22
|
-
}
|
20
|
+
}.freeze
|
23
21
|
|
24
22
|
def initialize(args = ARGV)
|
25
23
|
@options = parse_args(args)
|
@@ -28,7 +26,7 @@ module Aws
|
|
28
26
|
end
|
29
27
|
|
30
28
|
def set_environment
|
31
|
-
@environment = @options[:environment] || ENV[
|
29
|
+
@environment = @options[:environment] || ENV['APP_ENV'] || ENV['RAILS_ENV'] || ENV['RACK_ENV'] || 'development'
|
32
30
|
end
|
33
31
|
|
34
32
|
def run
|
@@ -42,10 +40,9 @@ module Aws
|
|
42
40
|
.merge(@options.to_h)
|
43
41
|
validate_config
|
44
42
|
# ensure we have a logger configured
|
45
|
-
@logger = @options[:logger] || ActiveSupport::Logger.new(
|
43
|
+
@logger = @options[:logger] || ActiveSupport::Logger.new($stdout)
|
46
44
|
@logger.info("Starting Poller with options=#{@options}")
|
47
45
|
|
48
|
-
|
49
46
|
Signal.trap('INT') { raise Interrupt }
|
50
47
|
Signal.trap('TERM') { raise Interrupt }
|
51
48
|
@executor = Executor.new(max_threads: @options[:threads], logger: @logger, max_queue: @options[:backpressure])
|
@@ -78,9 +75,7 @@ module Aws
|
|
78
75
|
# in order
|
79
76
|
# Jobs with different message_group_id will be processed in
|
80
77
|
# parallel and may be out of order.
|
81
|
-
if Aws::Rails::SqsActiveJob.fifo?(queue_url)
|
82
|
-
poller_options[:max_number_of_messages] = 1
|
83
|
-
end
|
78
|
+
poller_options[:max_number_of_messages] = 1 if Aws::Rails::SqsActiveJob.fifo?(queue_url)
|
84
79
|
|
85
80
|
single_message = poller_options[:max_number_of_messages] == 1
|
86
81
|
|
@@ -89,35 +84,53 @@ module Aws
|
|
89
84
|
@logger.info "Processing batch of #{msgs.length} messages"
|
90
85
|
msgs.each do |msg|
|
91
86
|
@executor.execute(Aws::SQS::Message.new(
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
87
|
+
queue_url: queue_url,
|
88
|
+
receipt_handle: msg.receipt_handle,
|
89
|
+
data: msg,
|
90
|
+
client: client
|
91
|
+
))
|
97
92
|
end
|
98
93
|
end
|
99
94
|
end
|
100
95
|
|
101
96
|
def boot_rails
|
102
97
|
ENV['RACK_ENV'] = ENV['RAILS_ENV'] = @environment
|
103
|
-
require
|
104
|
-
require File.expand_path(
|
98
|
+
require 'rails'
|
99
|
+
require File.expand_path('config/environment.rb')
|
105
100
|
end
|
106
101
|
|
107
102
|
def parse_args(argv)
|
108
103
|
out = {}
|
109
|
-
parser = ::OptionParser.new
|
110
|
-
opts.on(
|
111
|
-
opts.on(
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
opts.on(
|
116
|
-
|
117
|
-
|
104
|
+
parser = ::OptionParser.new do |opts|
|
105
|
+
opts.on('-q', '--queue STRING', '[Required] Queue to poll') { |a| out[:queue] = a }
|
106
|
+
opts.on('-e', '--environment STRING',
|
107
|
+
'Rails environment (defaults to development). You can also use the APP_ENV or RAILS_ENV environment variables to specify the environment.') do |a|
|
108
|
+
out[:environment] = a
|
109
|
+
end
|
110
|
+
opts.on('-t', '--threads INTEGER', Integer,
|
111
|
+
'The maximum number of worker threads to create. Defaults to 2x the number of processors available on this system.') do |a|
|
112
|
+
out[:threads] = a
|
113
|
+
end
|
114
|
+
opts.on('-b', '--backpressure INTEGER', Integer,
|
115
|
+
'The maximum number of messages to have waiting in the Executor queue. This should be a low, but non zero number. Messages in the Executor queue cannot be picked up by other processes and will slow down shutdown.') do |a|
|
116
|
+
out[:backpressure] = a
|
117
|
+
end
|
118
|
+
opts.on('-m', '--max_messages INTEGER', Integer,
|
119
|
+
'Max number of messages to receive in a batch from SQS.') do |a|
|
120
|
+
out[:max_messages] = a
|
121
|
+
end
|
122
|
+
opts.on('-v', '--visibility_timeout INTEGER', Integer,
|
123
|
+
'The visibility timeout is the number of seconds that a message will not be processable by any other consumers. You should set this value to be longer than your expected job runtime to prevent other processes from picking up an running job. See the SQS Visibility Timeout Documentation at https://docs.aws.amazon.com/AWSSimpleQueueService/latest/SQSDeveloperGuide/sqs-visibility-timeout.html.') do |a|
|
124
|
+
out[:visibility_timeout] = a
|
125
|
+
end
|
126
|
+
opts.on('-s', '--shutdown_timeout INTEGER', Integer,
|
127
|
+
'The amount of time to wait for a clean shutdown. Jobs that are unable to complete in this time will not be deleted from the SQS queue and will be retryable after the visibility timeout.') do |a|
|
128
|
+
out[:shutdown_timeout] = a
|
129
|
+
end
|
130
|
+
end
|
118
131
|
|
119
|
-
parser.banner =
|
120
|
-
parser.on_tail
|
132
|
+
parser.banner = 'aws_sqs_active_job [options]'
|
133
|
+
parser.on_tail '-h', '--help', 'Show help' do
|
121
134
|
puts parser
|
122
135
|
exit 1
|
123
136
|
end
|
data/lib/aws-sdk-rails.rb
CHANGED
@@ -5,6 +5,7 @@ require_relative 'aws/rails/sesv2_mailer'
|
|
5
5
|
require_relative 'aws/rails/railtie'
|
6
6
|
require_relative 'aws/rails/notifications'
|
7
7
|
require_relative 'aws/rails/sqs_active_job/configuration'
|
8
|
+
require_relative 'aws/rails/sqs_active_job/deduplication'
|
8
9
|
require_relative 'aws/rails/sqs_active_job/executor'
|
9
10
|
require_relative 'aws/rails/sqs_active_job/job_runner'
|
10
11
|
require_relative 'aws/rails/sqs_active_job/lambda_handler'
|