Skip to content

Commit

Permalink
When failing to contact the redis instance, schedule a index run
Browse files Browse the repository at this point in the history
  • Loading branch information
tcarmet committed Jun 3, 2024
1 parent 7478515 commit b5fae7d
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions runner_manager/routers/_health.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,28 @@

from fastapi import APIRouter, Depends, Response
from redis import Redis
from rq import Queue, Retry

from runner_manager.dependencies import get_redis
from runner_manager.dependencies import get_redis, get_queue
from runner_manager.jobs.startup import indexing

router = APIRouter(prefix="/_health")

log = logging.getLogger(__name__)


@router.get("/", status_code=200)
def healthcheck(r: Redis = Depends(get_redis)):
def healthcheck(r: Redis = Depends(get_redis), queue: Queue = Depends(get_queue)):
"""Healthcheck endpoint that answers to GET requests on /_health"""

try:
r.ping()
except Exception as exp:
log.error("Redis healthcheck failed: %s", exp)
# In the case where redis is rebooting
# when the service will be back up,
# it will need to create indexes for search to work
queue.enqueue(indexing, retry=Retry(max=3, interval=[30, 60, 120]))
return Response(status_code=500)

return Response(status_code=200)

0 comments on commit b5fae7d

Please sign in to comment.