Soumik555 commited on
Commit
2cea1af
·
1 Parent(s): 0f480e0

added upstash

Browse files
Files changed (1) hide show
  1. pinecone_keep_alive_service.py +10 -10
pinecone_keep_alive_service.py CHANGED
@@ -19,7 +19,6 @@ load_dotenv()
19
  keys = os.getenv("PINECONE_API_KEYS", "").split(",")
20
 
21
 
22
-
23
  class PineconePingResponse(BaseModel):
24
  service_name: str
25
  success: bool
@@ -56,35 +55,36 @@ def ping_all_pinecone_indexes() -> PineconePingAllResponse:
56
  )
57
  continue
58
 
 
59
  for index in indexes:
 
60
  try:
61
- stats = pc.Index(index.name).describe_index_stats()
62
-
63
- # 🔑 Make sure it's plain dict
64
  stats = dict(stats) if not isinstance(stats, dict) else stats
65
 
66
- logger.info(f"[{short_key}] ping {index.name} ✓")
67
  results.append(
68
  PineconePingResponse(
69
- service_name=f"pinecone-{index.name}",
70
  success=True,
71
  error=None,
72
  time=datetime.utcnow().isoformat(),
73
  api_key=short_key,
74
- index=index.name,
75
  stats=stats,
76
  )
77
  )
78
  except Exception as e:
79
- logger.error(f"[{short_key}] ping {index.name} ✗: {e}")
80
  results.append(
81
  PineconePingResponse(
82
- service_name=f"pinecone-{index.name}",
83
  success=False,
84
  error=str(e),
85
  time=datetime.utcnow().isoformat(),
86
  api_key=short_key,
87
- index=index.name,
88
  )
89
  )
90
 
 
19
  keys = os.getenv("PINECONE_API_KEYS", "").split(",")
20
 
21
 
 
22
  class PineconePingResponse(BaseModel):
23
  service_name: str
24
  success: bool
 
55
  )
56
  continue
57
 
58
+ # iterate over index list safely
59
  for index in indexes:
60
+ index_name = index if isinstance(index, str) else getattr(index, "name", str(index))
61
  try:
62
+ # always ensure we’re calling with a string name
63
+ stats = pc.Index(index_name).describe_index_stats()
 
64
  stats = dict(stats) if not isinstance(stats, dict) else stats
65
 
66
+ logger.info(f"[{short_key}] ping {index_name} ✓")
67
  results.append(
68
  PineconePingResponse(
69
+ service_name=f"pinecone-{index_name}",
70
  success=True,
71
  error=None,
72
  time=datetime.utcnow().isoformat(),
73
  api_key=short_key,
74
+ index=index_name,
75
  stats=stats,
76
  )
77
  )
78
  except Exception as e:
79
+ logger.error(f"[{short_key}] ping {index_name} ✗: {e}")
80
  results.append(
81
  PineconePingResponse(
82
+ service_name=f"pinecone-{index_name}",
83
  success=False,
84
  error=str(e),
85
  time=datetime.utcnow().isoformat(),
86
  api_key=short_key,
87
+ index=index_name,
88
  )
89
  )
90