Make create_table wait for table#8
Merged
eredi93 merged 2 commits intoeredi93:masterfrom Jul 23, 2018
gordonbondon:create_table
Merged
Make create_table wait for table#8eredi93 merged 2 commits intoeredi93:masterfrom gordonbondon:create_table
eredi93 merged 2 commits intoeredi93:masterfrom
gordonbondon:create_table
Conversation
eredi93
reviewed
Jul 22, 2018
| }, | ||
| table_name: table | ||
| ) | ||
| begin |
Owner
There was a problem hiding this comment.
this method is becoming quite big 😬
can you split it into 3 smaller private methods that then gets called by the create_table method?
something like:
def create_table
create_ddb_table
wait_until_ddb_table_exists
set_ddb_table_ttl
end
private def create_ddb_table
client.create_table(
...
)
rescue Aws::DynamoDB::Errors::ResourceInUseException => e
case e.massage
when "Table already exists: #{table}"
Marloss.logger.warn("DynamoDB table #{table} already exists")
else
raise
end
end
private def wait_until_ddb_table_exists
client.wait_until(:table_exists, table_name: table) do |w|
w.max_attempts = 10
w.delay = 1
end
rescue Aws::Waiters::Errors::WaiterFailed => e
Marloss.logger.error("Failed waiting for initialization of table #{table}")
raise
end
private def set_ddb_table_ttl
client.update_time_to_live(
...
)
rescue Aws::DynamoDB::Errors::ValidationException => e
case e.message
when "TimeToLive is already enabled"
Marloss.logger.warn("TTL attribute is already configured for table #{table}")
else
raise
end
end
Contributor
Author
There was a problem hiding this comment.
How about keeping create and wait in one method and splitting out ttl?
Owner
There was a problem hiding this comment.
that could cause confusion whether the TTL is required or not. I think exposing a simple method would create a better user experience
Contributor
Author
There was a problem hiding this comment.
sounds fair. I've added separate wait function
eredi93
reviewed
Jul 22, 2018
|
|
||
| # refresh the lock once | ||
| locker.refresh | ||
| locker.refresh_lock |
eredi93
reviewed
Jul 23, 2018
| end | ||
|
|
||
| begin | ||
| client.wait_until(:table_exists, table_name: table) do |w| |
Owner
There was a problem hiding this comment.
why not splitting the waiting to a separate method as I proposed?
eredi93
reviewed
Jul 23, 2018
| end | ||
|
|
||
| private def create_ddb_table | ||
| begin |
Owner
|
@gordonbondon Thanks you for getting this PR together! 🙇 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
It takes some time to initialize DynamoDB table, and previously I was getting this errors on creation:
or
Plus I made this call idempotent, allowing to make
create_tablecall on existing tables.