From b7b9acb2953968f19b4c9fc55d52ef30928a443e Mon Sep 17 00:00:00 2001 From: "randy.pierce" Date: Tue, 13 Feb 2024 09:47:59 -0700 Subject: [PATCH 1/2] add a retry for couchbase connection --- src/vxingest/builder_common/ingest_manager.py | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/vxingest/builder_common/ingest_manager.py b/src/vxingest/builder_common/ingest_manager.py index 837c48c..e0ea5fc 100644 --- a/src/vxingest/builder_common/ingest_manager.py +++ b/src/vxingest/builder_common/ingest_manager.py @@ -22,6 +22,7 @@ from couchbase.auth import PasswordAuthenticator from couchbase.cluster import Cluster from couchbase.exceptions import TimeoutException +from couchbase.exceptions import CouchbaseException from couchbase.options import ClusterOptions, ClusterTimeoutOptions logger = logging.getLogger(__name__) @@ -114,9 +115,17 @@ def connect_cb(self): ), timeout_options=timeout_options, ) - self.cluster = Cluster( - "couchbase://" + self.cb_credentials["host"], options - ) + _attempts = 0 + while _attempts < 3: + try: + self.cluster = Cluster( + "couchbase://" + self.cb_credentials["host"], options + ) + except CouchbaseException as _e: + time.sleep(5) + _attempts = _attempts + 1 + if _attempts == 3: + raise _e self.collection = self.cluster.bucket( self.cb_credentials["bucket"] ).collection(self.cb_credentials["collection"]) From 35c6aadba7d0d6ff042f332189bf9da67c3c704f Mon Sep 17 00:00:00 2001 From: "randy.pierce" Date: Tue, 13 Feb 2024 10:17:55 -0700 Subject: [PATCH 2/2] fix ruff setting and fix bad raise exception --- pyproject.toml | 5 +++-- src/vxingest/builder_common/ingest_manager.py | 7 ++++--- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index ac65a88..80bc39e 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -48,7 +48,8 @@ exclude = [ "scripts", "meta_update_middleware", ] -output-format="full" +output-format="pylint" + # For a list of available rules, see: https://docs.astral.sh/ruff/rules/ lint.select = [ @@ -67,4 +68,4 @@ lint.select = [ lint.ignore = [ "E501", # Supress line-too-long warnings: trust the formatter's judgement on this one. "W505", # Supress line-too-long warnings: trust the formatter's judgement on this one. -] \ No newline at end of file +] diff --git a/src/vxingest/builder_common/ingest_manager.py b/src/vxingest/builder_common/ingest_manager.py index e0ea5fc..52554d7 100644 --- a/src/vxingest/builder_common/ingest_manager.py +++ b/src/vxingest/builder_common/ingest_manager.py @@ -21,8 +21,7 @@ import pyproj # noqa: F401 from couchbase.auth import PasswordAuthenticator from couchbase.cluster import Cluster -from couchbase.exceptions import TimeoutException -from couchbase.exceptions import CouchbaseException +from couchbase.exceptions import CouchbaseException, TimeoutException from couchbase.options import ClusterOptions, ClusterTimeoutOptions logger = logging.getLogger(__name__) @@ -125,7 +124,9 @@ def connect_cb(self): time.sleep(5) _attempts = _attempts + 1 if _attempts == 3: - raise _e + raise CouchbaseException( + "Could not connect to couchbase after 3 attempts" + ) self.collection = self.cluster.bucket( self.cb_credentials["bucket"] ).collection(self.cb_credentials["collection"])