Spaces:
Sleeping
Sleeping
Update app/main.py
Browse files- app/main.py +6 -4
app/main.py
CHANGED
|
@@ -55,6 +55,11 @@ class Sync:
|
|
| 55 |
self._stop = threading.Event()
|
| 56 |
|
| 57 |
def start(self):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 58 |
threading.Thread(target=self._run, name="rag-sync", daemon=True).start()
|
| 59 |
|
| 60 |
def stop(self):
|
|
@@ -115,10 +120,8 @@ def create_app(embedder: Embedder | None = None, *, sync_on_start: bool = True)
|
|
| 115 |
|
| 116 |
@asynccontextmanager
|
| 117 |
async def lifespan(_: FastAPI):
|
| 118 |
-
if sync_on_start
|
| 119 |
sync.start()
|
| 120 |
-
elif sync_on_start:
|
| 121 |
-
log.warning("APP_URL or RAG_SECRET missing: the index only receives pushes from the app")
|
| 122 |
yield
|
| 123 |
sync.stop()
|
| 124 |
|
|
@@ -162,4 +165,3 @@ def create_app(embedder: Embedder | None = None, *, sync_on_start: bool = True)
|
|
| 162 |
return {"status": "scheduled"}
|
| 163 |
|
| 164 |
return app
|
| 165 |
-
|
|
|
|
| 55 |
self._stop = threading.Event()
|
| 56 |
|
| 57 |
def start(self):
|
| 58 |
+
"""Start the background sync, or warn when the app to read from is not configured."""
|
| 59 |
+
if not (self.app_url and self.secret):
|
| 60 |
+
log.warning("APP_URL or RAG_SECRET missing: the index only receives pushes from the app")
|
| 61 |
+
return
|
| 62 |
+
log.info("Reading the export from %s/api/rag/export", self.app_url)
|
| 63 |
threading.Thread(target=self._run, name="rag-sync", daemon=True).start()
|
| 64 |
|
| 65 |
def stop(self):
|
|
|
|
| 120 |
|
| 121 |
@asynccontextmanager
|
| 122 |
async def lifespan(_: FastAPI):
|
| 123 |
+
if sync_on_start:
|
| 124 |
sync.start()
|
|
|
|
|
|
|
| 125 |
yield
|
| 126 |
sync.stop()
|
| 127 |
|
|
|
|
| 165 |
return {"status": "scheduled"}
|
| 166 |
|
| 167 |
return app
|
|
|