Browse Source

Add MongoDB check for `/readyz`

master
Lauri Võsandi 4 months ago committed by Lauri Võsandi
parent
commit
8fc9a3d065
  1. 12
      camdetect.py
  2. 9
      mongo-init.sh

12
camdetect.py

@ -8,6 +8,7 @@ import io @@ -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): @@ -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")

9
mongo-init.sh

@ -1,11 +1,4 @@ @@ -1,11 +1,4 @@
#!/bin/bash
mongo <<EOF
rs.initiate({
_id: 'rs0',
members: [
{_id: 0, host: '127.0.0.1:27017'}
]
})
rs.initiate()
EOF

Loading…
Cancel
Save