Skip to content

Commit

Permalink
Merge cdba15e into 66c8659
Browse files Browse the repository at this point in the history
  • Loading branch information
HLH15 committed Apr 13, 2021
2 parents 66c8659 + cdba15e commit 358792f
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 2 deletions.
4 changes: 4 additions & 0 deletions README.md
Expand Up @@ -1126,6 +1126,10 @@ Listed below are all configuration options.
* `http_read_timeout`:The number of seconds to wait for HTTP response
data. Default option value is `nil`. If not specified effected value
is `60`
* `http_proxy`: A proxy to send requests through. Default option value is `nil`.
* `create_table_enabled`: if `true`, Dynamoid creates table if table not exist;
if `false`, Dynamoid logs error message for not able to create table in DynamoDB.
Default is `false`


## Concurrency
Expand Down
7 changes: 6 additions & 1 deletion lib/dynamoid/adapter_plugin/aws_sdk_v3.rb
Expand Up @@ -67,7 +67,7 @@ class AwsSdkV3
}
BATCH_WRITE_ITEM_REQUESTS_LIMIT = 25

CONNECTION_CONFIG_OPTIONS = %i[endpoint region http_continue_timeout http_idle_timeout http_open_timeout http_read_timeout].freeze
CONNECTION_CONFIG_OPTIONS = %i[endpoint region http_continue_timeout http_idle_timeout http_open_timeout http_read_timeout http_proxy].freeze

attr_reader :table_cache

Expand Down Expand Up @@ -282,6 +282,11 @@ def batch_delete_item(options)
# @option options [Boolean] sync Wait for table status to be ACTIVE?
# @since 1.0.0
def create_table(table_name, key = :id, options = {})
unless Dynamoid.config.create_table_enabled
Dynamoid.logger.error "Table #{table_name} is not created as create_table_enabled is disabled"
return false
end

Dynamoid.logger.info "Creating #{table_name} table. This could take a while."
CreateTable.new(client, table_name, key, options).call
true
Expand Down
2 changes: 2 additions & 0 deletions lib/dynamoid/config.rb
Expand Up @@ -59,6 +59,8 @@ module Config
option :http_idle_timeout, default: nil # - default: 5
option :http_open_timeout, default: nil # - default: 15
option :http_read_timeout, default: nil # - default: 60
option :http_proxy, default: nil
option :create_table_enabled, default: true

# The default logger for Dynamoid: either the Rails logger or just stdout.
#
Expand Down
4 changes: 3 additions & 1 deletion spec/dynamoid/adapter_plugin/aws_sdk_v3_spec.rb
Expand Up @@ -1242,11 +1242,13 @@ def dynamo_request(table_name, scan_hash = {}, select_opts = {})

before do
Dynamoid.configure.http_open_timeout = 30
Dynamoid.configure.http_proxy = 'http://proxy'
end

it 'not nil options entried' do
expect(subject.keys).to contain_exactly(:endpoint, :log_formatter, :log_level, :logger, :http_open_timeout)
expect(subject.keys).to contain_exactly(:endpoint, :log_formatter, :log_level, :logger, :http_open_timeout, :http_proxy)
expect(subject[:http_open_timeout]).to eq 30
expect(subject[:http_proxy]).to eq 'http://proxy'
end
end
end

0 comments on commit 358792f

Please sign in to comment.