From e54ad1ddb78ab6a3f08a03156d82c9de6a62c63c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lauri=20V=C3=B5sandi?= Date: Wed, 24 Aug 2022 23:02:25 +0300 Subject: [PATCH] Reorder readiness check --- camdetect.py | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/camdetect.py b/camdetect.py index b66dd01..0156071 100755 --- a/camdetect.py +++ b/camdetect.py @@ -484,6 +484,16 @@ async def stream_wrapper(request): @app.route("/readyz") async def ready_check(request): + if app.ctx.mask is None: + return response.text("Not enough frames", status=503) + + # Check if Mongo is accessible + 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) + # Check if S3 is accessible session = aioboto3.Session() async with session.resource("s3", @@ -492,15 +502,6 @@ async def ready_check(request): endpoint_url=S3_ENDPOINT_URL) as s3: bucket = await s3.Bucket(S3_BUCKET_NAME) await bucket.upload_fileobj(io.BytesIO(b"test"), "test") - - # Check if Mongo is accessible - 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")