Spaces:
Running
Running
Commit
·
eb40d09
1
Parent(s):
c08d4bb
refactor: remove old cleanup configurations and job scheduling from main
Browse files- api_monitor.py +31 -71
- requirements.txt +0 -1
api_monitor.py
CHANGED
@@ -85,44 +85,6 @@ def verify_mcp_api_key(api_key):
|
|
85 |
return {"success": False, "message": f"Key verification error: {str(e)}"}
|
86 |
|
87 |
|
88 |
-
def cleanup_old_configurations():
|
89 |
-
cleanup_situations = [
|
90 |
-
"""
|
91 |
-
DELETE FROM api_configurations
|
92 |
-
WHERE stop_at IS NOT NULL
|
93 |
-
AND stop_at < NOW() - INTERVAL '14 days';
|
94 |
-
""",
|
95 |
-
]
|
96 |
-
|
97 |
-
conn = None
|
98 |
-
try:
|
99 |
-
conn = connect_to_db()
|
100 |
-
with conn.cursor() as cur:
|
101 |
-
for raw_sql in cleanup_situations:
|
102 |
-
sql = raw_sql.strip()
|
103 |
-
if not sql:
|
104 |
-
continue
|
105 |
-
|
106 |
-
cur.execute(sql)
|
107 |
-
deleted = cur.rowcount
|
108 |
-
print(f"[CLEANUP] {deleted} rows deleted.")
|
109 |
-
conn.commit()
|
110 |
-
|
111 |
-
except Exception as e:
|
112 |
-
print(f"[ERROR] cleanup failed: {e}")
|
113 |
-
|
114 |
-
finally:
|
115 |
-
if conn:
|
116 |
-
conn.close()
|
117 |
-
|
118 |
-
|
119 |
-
def job_schedule():
|
120 |
-
sched = BlockingScheduler()
|
121 |
-
sched.add_job(cleanup_old_configurations, "cron", hour=0, minute=0)
|
122 |
-
print("cleanup job scheduled at 00:00 UTC")
|
123 |
-
sched.start()
|
124 |
-
|
125 |
-
|
126 |
def validate_api_configuration(
|
127 |
mcp_api_key,
|
128 |
name,
|
@@ -1016,41 +978,39 @@ import asyncio
|
|
1016 |
|
1017 |
|
1018 |
async def main():
|
1019 |
-
|
1020 |
-
|
1021 |
-
|
1022 |
-
|
1023 |
-
|
1024 |
-
|
1025 |
-
|
1026 |
-
|
1027 |
-
|
1028 |
-
|
1029 |
-
|
1030 |
-
|
1031 |
-
|
1032 |
-
|
1033 |
-
|
1034 |
-
|
1035 |
-
|
1036 |
-
|
1037 |
-
|
1038 |
-
|
1039 |
-
|
1040 |
-
|
1041 |
-
|
1042 |
-
|
1043 |
-
|
1044 |
-
|
1045 |
-
# print()
|
1046 |
-
# print()
|
1047 |
|
1048 |
await asyncio.sleep(10)
|
1049 |
-
|
1050 |
-
|
1051 |
-
|
1052 |
-
|
1053 |
-
|
1054 |
|
1055 |
|
1056 |
if __name__ == "__main__":
|
|
|
85 |
return {"success": False, "message": f"Key verification error: {str(e)}"}
|
86 |
|
87 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
88 |
def validate_api_configuration(
|
89 |
mcp_api_key,
|
90 |
name,
|
|
|
978 |
|
979 |
|
980 |
async def main():
|
981 |
+
|
982 |
+
validation_response = validate_api_configuration(
|
983 |
+
mcp_api_key=os.getenv("MCP_API_KEY"),
|
984 |
+
name="Dog Facts API",
|
985 |
+
description="Monitor random dog facts from a free API",
|
986 |
+
method="GET",
|
987 |
+
base_url="https://dogapi.dog",
|
988 |
+
endpoint="api/v2/facts",
|
989 |
+
param_keys_values="",
|
990 |
+
header_keys_values="",
|
991 |
+
additional_params="{}",
|
992 |
+
schedule_interval_minutes=0.05,
|
993 |
+
stop_after_hours=1,
|
994 |
+
start_at="",
|
995 |
+
)
|
996 |
+
print(validation_response)
|
997 |
+
print()
|
998 |
+
print()
|
999 |
+
|
1000 |
+
activate_monitoring_response = await activate_monitoring(
|
1001 |
+
config_id=validation_response.get("config_id"),
|
1002 |
+
mcp_api_key="os.getenv('MCP_API_KEY')",
|
1003 |
+
)
|
1004 |
+
print(activate_monitoring_response)
|
1005 |
+
print()
|
1006 |
+
print()
|
|
|
|
|
1007 |
|
1008 |
await asyncio.sleep(10)
|
1009 |
+
response = retrieve_monitored_data(
|
1010 |
+
config_id=activate_monitoring_response.get("config_id"),
|
1011 |
+
mcp_api_key=os.getenv("MCP_API_KEY"),
|
1012 |
+
)
|
1013 |
+
print(json.dumps(response, indent=2, default=str))
|
1014 |
|
1015 |
|
1016 |
if __name__ == "__main__":
|
requirements.txt
CHANGED
@@ -62,5 +62,4 @@ tzlocal==5.3.1
|
|
62 |
urllib3==2.4.0
|
63 |
uvicorn==0.34.3
|
64 |
websockets==15.0.1
|
65 |
-
|
66 |
apscheduler==3.11.0
|
|
|
62 |
urllib3==2.4.0
|
63 |
uvicorn==0.34.3
|
64 |
websockets==15.0.1
|
|
|
65 |
apscheduler==3.11.0
|