From 766ed6846a61a7497e657b4ac1acfaf6ed40fceb Mon Sep 17 00:00:00 2001 From: Thomas Carmet <8408330+tcarmet@users.noreply.github.com> Date: Mon, 3 Jun 2024 23:10:14 +0000 Subject: [PATCH] When failing to contact the redis instance, schedule a index run --- runner_manager/routers/_health.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/runner_manager/routers/_health.py b/runner_manager/routers/_health.py index 916ded57..37dde533 100644 --- a/runner_manager/routers/_health.py +++ b/runner_manager/routers/_health.py @@ -2,8 +2,10 @@ 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_queue, get_redis +from runner_manager.jobs.startup import indexing router = APIRouter(prefix="/_health") @@ -11,13 +13,17 @@ @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)