Spaces:
Running
Running
added upstash
Browse files
pinecone_keep_alive_service.py
CHANGED
|
@@ -31,12 +31,22 @@ keys = os.getenv("PINECONE_API_KEYS", "").split(",")
|
|
| 31 |
|
| 32 |
# ---------- Pinecone Ping ----------
|
| 33 |
def ping_all_pinecone_indexes():
|
|
|
|
|
|
|
| 34 |
for key in filter(None, (k.strip() for k in keys)):
|
| 35 |
pc = Pinecone(api_key=key)
|
| 36 |
try:
|
| 37 |
indexes = pc.list_indexes() # This returns IndexModel objects
|
| 38 |
except Exception as e:
|
| 39 |
logger.error(f"[{key[:5]}…] failed to list indexes: {e}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 40 |
continue
|
| 41 |
|
| 42 |
for index in indexes:
|
|
@@ -49,8 +59,7 @@ def ping_all_pinecone_indexes():
|
|
| 49 |
error=None,
|
| 50 |
time=datetime.now().isoformat(),
|
| 51 |
)
|
| 52 |
-
|
| 53 |
-
return final_response
|
| 54 |
except Exception as e:
|
| 55 |
logger.error(f"[{key[:5]}…] ping {index.name} ✗: {e}")
|
| 56 |
result = PineconePingResponse(
|
|
@@ -59,6 +68,7 @@ def ping_all_pinecone_indexes():
|
|
| 59 |
error=str(e),
|
| 60 |
time=datetime.now().isoformat(),
|
| 61 |
)
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
|
|
|
|
|
| 31 |
|
| 32 |
# ---------- Pinecone Ping ----------
|
| 33 |
def ping_all_pinecone_indexes():
|
| 34 |
+
results = [] # Collect all results here
|
| 35 |
+
|
| 36 |
for key in filter(None, (k.strip() for k in keys)):
|
| 37 |
pc = Pinecone(api_key=key)
|
| 38 |
try:
|
| 39 |
indexes = pc.list_indexes() # This returns IndexModel objects
|
| 40 |
except Exception as e:
|
| 41 |
logger.error(f"[{key[:5]}…] failed to list indexes: {e}")
|
| 42 |
+
# Create a response for the failed API key
|
| 43 |
+
result = PineconePingResponse(
|
| 44 |
+
idx_name=f"API_KEY_{key[:5]}…",
|
| 45 |
+
success=False,
|
| 46 |
+
error=f"Failed to list indexes: {e}",
|
| 47 |
+
time=datetime.now().isoformat(),
|
| 48 |
+
)
|
| 49 |
+
results.append(result)
|
| 50 |
continue
|
| 51 |
|
| 52 |
for index in indexes:
|
|
|
|
| 59 |
error=None,
|
| 60 |
time=datetime.now().isoformat(),
|
| 61 |
)
|
| 62 |
+
results.append(result)
|
|
|
|
| 63 |
except Exception as e:
|
| 64 |
logger.error(f"[{key[:5]}…] ping {index.name} ✗: {e}")
|
| 65 |
result = PineconePingResponse(
|
|
|
|
| 68 |
error=str(e),
|
| 69 |
time=datetime.now().isoformat(),
|
| 70 |
)
|
| 71 |
+
results.append(result)
|
| 72 |
+
|
| 73 |
+
# Return all collected results at the end
|
| 74 |
+
return PineconeAllPingResponse(pinecone_services=results)
|