From 8fc9a3d0655d55256c059919950536228975a397 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lauri=20V=C3=B5sandi?= Date: Sun, 27 Feb 2022 17:02:55 +0200 Subject: [PATCH] Add MongoDB check for `/readyz` --- camdetect.py | 12 +++++++++--- mongo-init.sh | 9 +-------- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/camdetect.py b/camdetect.py index 25b92ed..61f0bfb 100755 --- a/camdetect.py +++ b/camdetect.py @@ -8,6 +8,7 @@ import io import json import numpy as np import os +import pymongo import signal import sys from datetime import datetime, timedelta @@ -432,9 +433,14 @@ async def stream_wrapper(request): @app.route("/readyz") async def ready_check(request): - if app.ctx.mask is not None: - return response.text("OK") - return response.text("Not enough frames", status=503) + try: + async for i in app.ctx.coll.find().limit(1): + break + except pymongo.errors.ServerSelectionTimeoutError: + return response.text("MongoDB server selection timeout", status=503) + if app.ctx.mask is None: + return response.text("Not enough frames", status=503) + return response.text("OK") @app.route("/event") diff --git a/mongo-init.sh b/mongo-init.sh index 5dacf7a..00d616d 100644 --- a/mongo-init.sh +++ b/mongo-init.sh @@ -1,11 +1,4 @@ #!/bin/bash mongo <