Skip to content

Commit

Permalink
add a retry for couchbase connection (#327)
Browse files Browse the repository at this point in the history
this is pretty easy so going ahead and merging
  • Loading branch information
randytpierce authored Feb 13, 2024
2 parents 3a2bb3b + 35c6aad commit e5e7488
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
5 changes: 3 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand All @@ -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.
]
]
18 changes: 14 additions & 4 deletions src/vxingest/builder_common/ingest_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +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, TimeoutException
from couchbase.options import ClusterOptions, ClusterTimeoutOptions

logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -114,9 +114,19 @@ 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 CouchbaseException(
"Could not connect to couchbase after 3 attempts"
)
self.collection = self.cluster.bucket(
self.cb_credentials["bucket"]
).collection(self.cb_credentials["collection"])
Expand Down

0 comments on commit e5e7488

Please sign in to comment.