Spaces:
Running
Running
Commit
·
040bfbf
1
Parent(s):
41d2577
works and stuffs event data in db
Browse files- api_monitor.py +39 -1
api_monitor.py
CHANGED
@@ -394,7 +394,7 @@ async def activate_monitoring(config_id, mcp_api_key):
|
|
394 |
}
|
395 |
# Extract scheduling parameters
|
396 |
name = config.get("name", "Unknown")
|
397 |
-
schedule_interval_minutes = config.get("schedule_interval_minutes", 20)
|
398 |
stop_at = config.get("stop_at")
|
399 |
start_at = config.get("time_to_start")
|
400 |
if not start_at:
|
@@ -411,6 +411,44 @@ async def activate_monitoring(config_id, mcp_api_key):
|
|
411 |
def dummy_job():
|
412 |
now = datetime.now()
|
413 |
next_call = now + timedelta(minutes=schedule_interval_minutes)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
414 |
return {
|
415 |
"success": True,
|
416 |
"message": f"Scheduler activated for '{name}'",
|
|
|
394 |
}
|
395 |
# Extract scheduling parameters
|
396 |
name = config.get("name", "Unknown")
|
397 |
+
schedule_interval_minutes = float(config.get("schedule_interval_minutes", 20))
|
398 |
stop_at = config.get("stop_at")
|
399 |
start_at = config.get("time_to_start")
|
400 |
if not start_at:
|
|
|
411 |
def dummy_job():
|
412 |
now = datetime.now()
|
413 |
next_call = now + timedelta(minutes=schedule_interval_minutes)
|
414 |
+
print(f"Executing job for {name} at {now.isoformat()}. Next call at {next_call.isoformat()}")
|
415 |
+
try:
|
416 |
+
job_conn = connect_to_db()
|
417 |
+
job_cur = job_conn.cursor()
|
418 |
+
# Mark config as active (only once, on first run)
|
419 |
+
job_cur.execute(
|
420 |
+
"""
|
421 |
+
UPDATE api_configurations SET is_active = %s WHERE config_id = %s
|
422 |
+
""",
|
423 |
+
(True, config_id)
|
424 |
+
)
|
425 |
+
# Insert a dummy result into api_call_results
|
426 |
+
job_cur.execute(
|
427 |
+
"""
|
428 |
+
INSERT INTO api_call_results (
|
429 |
+
config_id, response_data, is_successful, error_message, called_at
|
430 |
+
) VALUES (%s, %s, %s, %s, %s)
|
431 |
+
""",
|
432 |
+
(
|
433 |
+
config_id,
|
434 |
+
json.dumps({
|
435 |
+
"success": True,
|
436 |
+
"message": f"Scheduler activated for '{name}'",
|
437 |
+
"config_id": config_id,
|
438 |
+
"schedule_interval_minutes": schedule_interval_minutes,
|
439 |
+
"stop_at": stop_at.isoformat(),
|
440 |
+
"next_call_at": next_call.isoformat(),
|
441 |
+
}),
|
442 |
+
True,
|
443 |
+
None,
|
444 |
+
now,
|
445 |
+
)
|
446 |
+
)
|
447 |
+
job_conn.commit()
|
448 |
+
job_cur.close()
|
449 |
+
job_conn.close()
|
450 |
+
except Exception as job_exc:
|
451 |
+
print(f"Dummy job DB error: {job_exc}")
|
452 |
return {
|
453 |
"success": True,
|
454 |
"message": f"Scheduler activated for '{name}'",
|