mirror of
https://github.com/NousResearch/hermes-agent.git
synced 2026-07-19 15:18:03 +00:00
🐛 fix(dashboard): offload cron profile scans
This commit is contained in:
parent
b6c7ebf028
commit
1fded709aa
2 changed files with 101 additions and 18 deletions
|
|
@ -6732,8 +6732,7 @@ def _find_cron_job_profile(job_id: str) -> Optional[str]:
|
|||
return None
|
||||
|
||||
|
||||
@app.get("/api/cron/jobs")
|
||||
async def list_cron_jobs(profile: str = "all"):
|
||||
def _list_cron_jobs_sync(profile: str = "all"):
|
||||
requested = (profile or "all").strip()
|
||||
if requested.lower() != "all":
|
||||
return _call_cron_for_profile(requested, "list_jobs", True)
|
||||
|
|
@ -6750,8 +6749,17 @@ async def list_cron_jobs(profile: str = "all"):
|
|||
return jobs
|
||||
|
||||
|
||||
@app.get("/api/cron/jobs/{job_id}")
|
||||
async def get_cron_job(job_id: str, profile: Optional[str] = None):
|
||||
async def _run_cron_dashboard_io(func, *args, **kwargs):
|
||||
"""Run cron dashboard profile/job I/O outside the FastAPI event loop."""
|
||||
return await asyncio.to_thread(func, *args, **kwargs)
|
||||
|
||||
|
||||
@app.get("/api/cron/jobs")
|
||||
async def list_cron_jobs(profile: str = "all"):
|
||||
return await _run_cron_dashboard_io(_list_cron_jobs_sync, profile)
|
||||
|
||||
|
||||
def _get_cron_job_sync(job_id: str, profile: Optional[str] = None):
|
||||
selected = profile or _find_cron_job_profile(job_id)
|
||||
if not selected:
|
||||
raise HTTPException(status_code=404, detail="Job not found")
|
||||
|
|
@ -6761,8 +6769,12 @@ async def get_cron_job(job_id: str, profile: Optional[str] = None):
|
|||
return job
|
||||
|
||||
|
||||
@app.get("/api/cron/jobs/{job_id}/runs")
|
||||
async def list_cron_job_runs(job_id: str, profile: Optional[str] = None, limit: int = 20):
|
||||
@app.get("/api/cron/jobs/{job_id}")
|
||||
async def get_cron_job(job_id: str, profile: Optional[str] = None):
|
||||
return await _run_cron_dashboard_io(_get_cron_job_sync, job_id, profile)
|
||||
|
||||
|
||||
def _list_cron_job_runs_sync(job_id: str, profile: Optional[str] = None, limit: int = 20):
|
||||
"""Run sessions produced by a cron job, newest first.
|
||||
|
||||
Cron runs are stored as ordinary sessions whose id is
|
||||
|
|
@ -6807,8 +6819,12 @@ async def list_cron_job_runs(job_id: str, profile: Optional[str] = None, limit:
|
|||
db.close()
|
||||
|
||||
|
||||
@app.post("/api/cron/jobs")
|
||||
async def create_cron_job(body: CronJobCreate, profile: str = "default"):
|
||||
@app.get("/api/cron/jobs/{job_id}/runs")
|
||||
async def list_cron_job_runs(job_id: str, profile: Optional[str] = None, limit: int = 20):
|
||||
return await _run_cron_dashboard_io(_list_cron_job_runs_sync, job_id, profile, limit)
|
||||
|
||||
|
||||
def _create_cron_job_sync(body: CronJobCreate, profile: str = "default"):
|
||||
try:
|
||||
return _call_cron_for_profile(
|
||||
profile,
|
||||
|
|
@ -6824,6 +6840,11 @@ async def create_cron_job(body: CronJobCreate, profile: str = "default"):
|
|||
raise HTTPException(status_code=400, detail=str(e))
|
||||
|
||||
|
||||
@app.post("/api/cron/jobs")
|
||||
async def create_cron_job(body: CronJobCreate, profile: str = "default"):
|
||||
return await _run_cron_dashboard_io(_create_cron_job_sync, body, profile)
|
||||
|
||||
|
||||
@app.get("/api/cron/delivery-targets")
|
||||
async def get_cron_delivery_targets():
|
||||
"""Delivery targets the cron dropdown should offer.
|
||||
|
|
@ -6852,8 +6873,7 @@ async def get_cron_delivery_targets():
|
|||
return {"targets": targets}
|
||||
|
||||
|
||||
@app.put("/api/cron/jobs/{job_id}")
|
||||
async def update_cron_job(job_id: str, body: CronJobUpdate, profile: Optional[str] = None):
|
||||
def _update_cron_job_sync(job_id: str, body: CronJobUpdate, profile: Optional[str] = None):
|
||||
selected = profile or _find_cron_job_profile(job_id)
|
||||
if not selected:
|
||||
raise HTTPException(status_code=404, detail="Job not found")
|
||||
|
|
@ -6866,8 +6886,12 @@ async def update_cron_job(job_id: str, body: CronJobUpdate, profile: Optional[st
|
|||
return job
|
||||
|
||||
|
||||
@app.post("/api/cron/jobs/{job_id}/pause")
|
||||
async def pause_cron_job(job_id: str, profile: Optional[str] = None):
|
||||
@app.put("/api/cron/jobs/{job_id}")
|
||||
async def update_cron_job(job_id: str, body: CronJobUpdate, profile: Optional[str] = None):
|
||||
return await _run_cron_dashboard_io(_update_cron_job_sync, job_id, body, profile)
|
||||
|
||||
|
||||
def _pause_cron_job_sync(job_id: str, profile: Optional[str] = None):
|
||||
selected = profile or _find_cron_job_profile(job_id)
|
||||
if not selected:
|
||||
raise HTTPException(status_code=404, detail="Job not found")
|
||||
|
|
@ -6877,8 +6901,12 @@ async def pause_cron_job(job_id: str, profile: Optional[str] = None):
|
|||
return job
|
||||
|
||||
|
||||
@app.post("/api/cron/jobs/{job_id}/resume")
|
||||
async def resume_cron_job(job_id: str, profile: Optional[str] = None):
|
||||
@app.post("/api/cron/jobs/{job_id}/pause")
|
||||
async def pause_cron_job(job_id: str, profile: Optional[str] = None):
|
||||
return await _run_cron_dashboard_io(_pause_cron_job_sync, job_id, profile)
|
||||
|
||||
|
||||
def _resume_cron_job_sync(job_id: str, profile: Optional[str] = None):
|
||||
selected = profile or _find_cron_job_profile(job_id)
|
||||
if not selected:
|
||||
raise HTTPException(status_code=404, detail="Job not found")
|
||||
|
|
@ -6888,8 +6916,12 @@ async def resume_cron_job(job_id: str, profile: Optional[str] = None):
|
|||
return job
|
||||
|
||||
|
||||
@app.post("/api/cron/jobs/{job_id}/trigger")
|
||||
async def trigger_cron_job(job_id: str, profile: Optional[str] = None):
|
||||
@app.post("/api/cron/jobs/{job_id}/resume")
|
||||
async def resume_cron_job(job_id: str, profile: Optional[str] = None):
|
||||
return await _run_cron_dashboard_io(_resume_cron_job_sync, job_id, profile)
|
||||
|
||||
|
||||
def _trigger_cron_job_sync(job_id: str, profile: Optional[str] = None):
|
||||
selected = profile or _find_cron_job_profile(job_id)
|
||||
if not selected:
|
||||
raise HTTPException(status_code=404, detail="Job not found")
|
||||
|
|
@ -6899,8 +6931,12 @@ async def trigger_cron_job(job_id: str, profile: Optional[str] = None):
|
|||
return job
|
||||
|
||||
|
||||
@app.delete("/api/cron/jobs/{job_id}")
|
||||
async def delete_cron_job(job_id: str, profile: Optional[str] = None):
|
||||
@app.post("/api/cron/jobs/{job_id}/trigger")
|
||||
async def trigger_cron_job(job_id: str, profile: Optional[str] = None):
|
||||
return await _run_cron_dashboard_io(_trigger_cron_job_sync, job_id, profile)
|
||||
|
||||
|
||||
def _delete_cron_job_sync(job_id: str, profile: Optional[str] = None):
|
||||
selected = profile or _find_cron_job_profile(job_id)
|
||||
if not selected:
|
||||
raise HTTPException(status_code=404, detail="Job not found")
|
||||
|
|
@ -6913,6 +6949,11 @@ async def delete_cron_job(job_id: str, profile: Optional[str] = None):
|
|||
return {"ok": True}
|
||||
|
||||
|
||||
@app.delete("/api/cron/jobs/{job_id}")
|
||||
async def delete_cron_job(job_id: str, profile: Optional[str] = None):
|
||||
return await _run_cron_dashboard_io(_delete_cron_job_sync, job_id, profile)
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# Automation Blueprints — parameterized automation blueprints. The dashboard renders the
|
||||
# slot schema as a form; submitting instantiates a real cron job via the same
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue