fix: double volatile TTLs to survive missed scheduler runs
TTL = 2x refresh interval ensures data remains valid even if a scheduled refresh is delayed or fails. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,102 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Quick script to check environmental data in Qdrant volatile cache."""
|
||||
|
||||
import asyncio
|
||||
import os
|
||||
import time
|
||||
from dotenv import load_dotenv
|
||||
|
||||
load_dotenv()
|
||||
|
||||
async def main():
|
||||
from qdrant_client import QdrantClient
|
||||
from qdrant_client.models import Filter, FieldCondition, MatchValue
|
||||
from src.config import get_settings
|
||||
|
||||
settings = get_settings()
|
||||
qdrant = QdrantClient(url=settings.qdrant_url)
|
||||
|
||||
user = "jpmschweitzer"
|
||||
collection = f"volatile_{user}"
|
||||
|
||||
print(f"\n{'='*60}")
|
||||
print(f"Volatile Data in Qdrant ({collection})")
|
||||
print(f"{'='*60}\n")
|
||||
|
||||
namespaces = ["weather", "air_quality", "forecast", "sun", "news"]
|
||||
|
||||
for ns in namespaces:
|
||||
try:
|
||||
results = qdrant.scroll(
|
||||
collection_name=collection,
|
||||
scroll_filter=Filter(
|
||||
must=[FieldCondition(key="namespace", match=MatchValue(value=ns))]
|
||||
),
|
||||
limit=10,
|
||||
with_payload=True,
|
||||
with_vectors=False,
|
||||
)
|
||||
|
||||
points = results[0]
|
||||
print(f"=== {ns.upper()} ({len(points)} records) ===")
|
||||
|
||||
if not points:
|
||||
print(" (no data)")
|
||||
print()
|
||||
continue
|
||||
|
||||
for point in points:
|
||||
payload = point.payload
|
||||
raw_data = payload.get("raw_data", {})
|
||||
|
||||
if ns == "weather":
|
||||
print(f" Temperature: {raw_data.get('temperature')}°C (feels like {raw_data.get('feels_like')}°C)")
|
||||
print(f" Conditions: {raw_data.get('conditions')}")
|
||||
print(f" Humidity: {raw_data.get('humidity')}%")
|
||||
print(f" Wind: {raw_data.get('wind_speed')} km/h")
|
||||
print(f" UV Index: {raw_data.get('uv_index')}")
|
||||
|
||||
elif ns == "air_quality":
|
||||
print(f" European AQI: {raw_data.get('aqi_european')}")
|
||||
print(f" US AQI: {raw_data.get('aqi_us')}")
|
||||
print(f" PM2.5: {raw_data.get('pm2_5')} µg/m³")
|
||||
print(f" PM10: {raw_data.get('pm10')} µg/m³")
|
||||
print(f" Ozone: {raw_data.get('ozone')} µg/m³")
|
||||
print(f" NO₂: {raw_data.get('nitrogen_dioxide')} µg/m³")
|
||||
|
||||
elif ns == "forecast":
|
||||
daily = raw_data.get("daily", [])
|
||||
for day in daily[:5]:
|
||||
print(f" {day.get('day_name', 'N/A')[:3]}: {day.get('temp_low'):.0f}-{day.get('temp_high'):.0f}°C, {day.get('conditions')}")
|
||||
|
||||
elif ns == "sun":
|
||||
print(f" Sunrise: {raw_data.get('sunrise')}")
|
||||
print(f" Sunset: {raw_data.get('sunset')}")
|
||||
print(f" Daylight: {raw_data.get('daylight_hours', 0):.1f} hours")
|
||||
|
||||
elif ns == "news":
|
||||
headlines = raw_data.get("headlines", [])
|
||||
print(f" Category: {raw_data.get('category', 'general')}")
|
||||
print(f" Headlines ({len(headlines)}):")
|
||||
for item in headlines[:5]:
|
||||
title = item.get("title", "")[:60]
|
||||
source = item.get("source", "")
|
||||
print(f" - [{source}] {title}...")
|
||||
|
||||
# Show TTL info
|
||||
ttl_expiry = payload.get("ttl_expiry")
|
||||
if ttl_expiry:
|
||||
remaining = (ttl_expiry / 1000) - time.time()
|
||||
if remaining > 0:
|
||||
print(f" TTL remaining: {int(remaining)}s ({int(remaining/60)} min)")
|
||||
else:
|
||||
print(f" TTL: EXPIRED")
|
||||
|
||||
print()
|
||||
|
||||
except Exception as e:
|
||||
print(f" Error fetching {ns}: {e}")
|
||||
print()
|
||||
|
||||
if __name__ == "__main__":
|
||||
asyncio.run(main())
|
||||
Reference in New Issue
Block a user