aboutsummaryrefslogtreecommitdiff
path: root/uploader/check_connections.py
diff options
context:
space:
mode:
Diffstat (limited to 'uploader/check_connections.py')
-rw-r--r--uploader/check_connections.py28
1 files changed, 28 insertions, 0 deletions
diff --git a/uploader/check_connections.py b/uploader/check_connections.py
new file mode 100644
index 0000000..2561e55
--- /dev/null
+++ b/uploader/check_connections.py
@@ -0,0 +1,28 @@
+"""Check the various connection used in the application"""
+import sys
+import traceback
+
+import redis
+import MySQLdb
+
+from uploader.db_utils import database_connection
+
+def check_redis(uri: str):
+ "Check the redis connection"
+ try:
+ with redis.Redis.from_url(uri) as rconn:
+ rconn.ping()
+ except redis.exceptions.ConnectionError as conn_err:
+ print(conn_err, file=sys.stderr)
+ print(traceback.format_exc(), file=sys.stderr)
+ sys.exit(1)
+
+def check_db(uri: str):
+ "Check the mysql connection"
+ try:
+ with database_connection(uri) as dbconn: # pylint: disable=[unused-variable]
+ pass
+ except MySQLdb.OperationalError as op_err:
+ print(op_err, file=sys.stderr)
+ print(traceback.format_exc(), file=sys.stderr)
+ sys.exit(1)