Make old telemetry server forward requests to new server

This commit is contained in:
Debanjum Singh Solanky 2023-06-05 07:46:41 +05:30
parent f6ceb22373
commit d13db2e666
2 changed files with 11 additions and 0 deletions

View file

@ -1,2 +1,3 @@
uvicorn uvicorn
fastapi fastapi
requests

View file

@ -7,6 +7,7 @@ from typing import Dict, List
from fastapi import FastAPI from fastapi import FastAPI
from fastapi import HTTPException from fastapi import HTTPException
import sqlite3 import sqlite3
import requests
import uvicorn import uvicorn
@ -25,6 +26,15 @@ def v1_telemetry(telemetry_data: List[Dict[str, str]]):
logger.error(error_message) logger.error(error_message)
raise HTTPException(status_code=500, detail=error_message) raise HTTPException(status_code=500, detail=error_message)
# POST request to new khoj telemetry server
try:
requests.post("https://telemetry.khoj.dev/v1/telemetry", json=telemetry_data)
except Exception as e:
raise HTTPException(
status_code=500,
detail="Could not POST equest to new khoj telemetry server. Contact developer to get this fixed.",
)
# Insert recieved telemetry data into SQLite db # Insert recieved telemetry data into SQLite db
logger.info(f"Insert row into telemetry table at {sqlfile}: {telemetry_data}") logger.info(f"Insert row into telemetry table at {sqlfile}: {telemetry_data}")
with sqlite3.connect(sqlfile) as conn: with sqlite3.connect(sqlfile) as conn: