Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/integration_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ on:
push:
branches:
- main
- feat/tortoise

permissions:
id-token: write # This is required for requesting the JWT
Expand Down
9 changes: 6 additions & 3 deletions aws_advanced_python_wrapper/custom_endpoint_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,8 @@ def _run(self):
len(endpoints),
endpoint_hostnames)

sleep(self._refresh_rate_ns / 1_000_000_000)
if self._stop_event.wait(self._refresh_rate_ns / 1_000_000_000):
break
continue

endpoint_info = CustomEndpointInfo.from_db_cluster_endpoint(endpoints[0])
Expand All @@ -178,7 +179,8 @@ def _run(self):
if cached_info is not None and cached_info == endpoint_info:
elapsed_time = perf_counter_ns() - start_ns
sleep_duration = max(0, self._refresh_rate_ns - elapsed_time)
sleep(sleep_duration / 1_000_000_000)
if self._stop_event.wait(sleep_duration / 1_000_000_000):
break
continue

logger.debug(
Expand All @@ -196,7 +198,8 @@ def _run(self):

elapsed_time = perf_counter_ns() - start_ns
sleep_duration = max(0, self._refresh_rate_ns - elapsed_time)
sleep(sleep_duration / 1_000_000_000)
if self._stop_event.wait(sleep_duration / 1_000_000_000):
break
continue
except InterruptedError as e:
raise e
Expand Down
28 changes: 28 additions & 0 deletions aws_advanced_python_wrapper/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,31 @@ class FailoverSuccessError(FailoverError):

class ReadWriteSplittingError(AwsWrapperError):
__module__ = "aws_advanced_python_wrapper"


class AsyncConnectionPoolError(AwsWrapperError):
__module__ = "aws_advanced_python_wrapper"


class PoolNotInitializedError(AsyncConnectionPoolError):
__module__ = "aws_advanced_python_wrapper"


class PoolClosingError(AsyncConnectionPoolError):
__module__ = "aws_advanced_python_wrapper"


class PoolExhaustedError(AsyncConnectionPoolError):
__module__ = "aws_advanced_python_wrapper"


class ConnectionReleasedError(AsyncConnectionPoolError):
__module__ = "aws_advanced_python_wrapper"


class PoolSizeLimitError(AsyncConnectionPoolError):
__module__ = "aws_advanced_python_wrapper"


class PoolHealthCheckError(AsyncConnectionPoolError):
__module__ = "aws_advanced_python_wrapper"
2 changes: 1 addition & 1 deletion aws_advanced_python_wrapper/iam_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ def _connect(self, host_info: HostInfo, props: Properties, connect_func: Callabl

is_cached_token = (token_info is not None and not token_info.is_expired())
if not self._plugin_service.is_login_exception(error=e) or not is_cached_token:
raise AwsWrapperError(Messages.get_formatted("IamAuthPlugin.ConnectException", e)) from e
raise
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to remove the wrapped error. If we get a failover and we get a network error, the failover plugin will not detect it.


# Login unsuccessful with cached token
# Try to generate a new token and try to connect again
Expand Down
47 changes: 47 additions & 0 deletions aws_advanced_python_wrapper/tortoise_orm/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License").
# You may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from tortoise.backends.base.config_generator import DB_LOOKUP


def cast_to_bool(value):
"""Generic function to cast various types to boolean."""
if isinstance(value, bool):
return value
if isinstance(value, str):
return value.lower() in ('true', '1', 'yes', 'on')
return bool(value)


# Register AWS MySQL backend
DB_LOOKUP["aws-mysql"] = {
"engine": "aws_advanced_python_wrapper.tortoise_orm.backends.mysql",
"vmap": {
"path": "database",
"hostname": "host",
"port": "port",
"username": "user",
"password": "password",
},
"defaults": {"port": 3306, "charset": "utf8mb4", "sql_mode": "STRICT_TRANS_TABLES"},
"cast": {
"minsize": int,
"maxsize": int,
"connect_timeout": int,
"echo": cast_to_bool,
"use_unicode": cast_to_bool,
"ssl": cast_to_bool,
"use_pure": cast_to_bool
},
}
13 changes: 13 additions & 0 deletions aws_advanced_python_wrapper/tortoise_orm/async_support/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License").
# You may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
Loading
Loading