Skip to content

Commit

Permalink
chore: try 11
Browse files Browse the repository at this point in the history
  • Loading branch information
sali72 committed Dec 10, 2024
1 parent a202320 commit 4e39ee2
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
2 changes: 0 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,4 @@ WORKDIR /app
COPY . /app/
RUN pip install --no-cache-dir -r requirements.txt

EXPOSE 10000

CMD [ "uvicorn" , "app.main:app", "--host", "0.0.0.0", "--port", "10000", "--reload"]
10 changes: 8 additions & 2 deletions database/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
MONGO_ROOT_PASSWORD = os.getenv("MONGO_ROOT_PASSWORD")
MONGO_HOST = os.getenv("MONGO_HOST")
MONGO_LOCAL_HOST = os.getenv("MONGO_LOCAL_HOST")
MONGO_ATLAS_CONNECTION_STRING = os.getenv("MONGO_ATLAS_CONNECTION_STRING")
TEST_MODE = os.getenv("TEST_MODE")

logging.basicConfig(level=logging.INFO)
Expand All @@ -33,7 +34,7 @@ async def connect_to_db():
port=27017,
serverSelectionTimeoutMS=10000,
)
else:
elif TEST_MODE == "false":
mongoengine.connect(
db=MONGO_DATABASE,
host=MONGO_HOST,
Expand All @@ -45,6 +46,11 @@ async def connect_to_db():
# authentication_source="admin",
serverSelectionTimeoutMS=10000,
)
elif TEST_MODE == "atlas":
mongoengine.connect(
host=MONGO_ATLAS_CONNECTION_STRING,
serverSelectionTimeoutMS=30000,
)

# Perform a simple operation to verify the connection
connection = get_connection()
Expand All @@ -55,7 +61,7 @@ async def connect_to_db():
await initialize_common_categories()
try:
if connection[MONGO_DATABASE].list_collection_names():
logger.info(" Connected to MongoDB successfully")
logger.info(f" Connected to MongoDB successfully, mode: {TEST_MODE}")
else:
logger.error(" Failed to connect to MongoDB")
except Exception as e:
Expand Down

0 comments on commit 4e39ee2

Please sign in to comment.