Skip to content

Commit

Permalink
added script for deployment to prompt for db readiness
Browse files Browse the repository at this point in the history
  • Loading branch information
SonOfLope committed Sep 10, 2023
1 parent ff96489 commit 0fd3efe
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions scripts/check_db.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import os
import pymongo
import sys

mongo_host = os.environ.get('MONGO_HOST')
mongo_port = os.environ.get('MONGO_PORT')
mongo_user = os.environ.get('MONGO_USER')
mongo_pass = os.environ.get('MONGO_PASSWORD')


try:
client = pymongo.MongoClient(f'mongodb://{mongo_user}:{mongo_pass}@{mongo_host}:{mongo_port}/')

client.server_info()
print(f"Connection à MongoDB réussie sur {mongo_host}:{mongo_port}")
sys.exit(0)

except Exception as e:
# En cas d'erreur, imprimez l'erreur (optionnel) et sortez avec un code de sortie 1
print(f"Erreur lors de la connexion à MongoDB : {e}")

0 comments on commit 0fd3efe

Please sign in to comment.