2023-06-01 18:40:12 +00:00
|
|
|
import logging
|
|
|
|
|
2024-10-23 15:57:36 +00:00
|
|
|
from fastapi import APIRouter
|
2023-06-01 18:40:12 +00:00
|
|
|
from fastapi.exceptions import HTTPException
|
|
|
|
|
2024-05-12 13:18:32 +00:00
|
|
|
from freqtrade.rpc.api_server.api_schemas import (
|
|
|
|
BackgroundTaskStatus,
|
|
|
|
)
|
2023-06-01 18:40:12 +00:00
|
|
|
from freqtrade.rpc.api_server.webserver_bgwork import ApiBG
|
|
|
|
|
|
|
|
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
|
|
# Private API, protected by authentication and webserver_mode dependency
|
|
|
|
router = APIRouter()
|
|
|
|
|
|
|
|
|
2024-10-04 05:06:27 +00:00
|
|
|
@router.get("/background", response_model=list[BackgroundTaskStatus], tags=["webserver"])
|
2024-05-12 07:12:53 +00:00
|
|
|
def background_job_list():
|
2024-05-12 14:51:11 +00:00
|
|
|
return [
|
|
|
|
{
|
|
|
|
"job_id": jobid,
|
|
|
|
"job_category": job["category"],
|
|
|
|
"status": job["status"],
|
|
|
|
"running": job["is_running"],
|
|
|
|
"progress": job.get("progress"),
|
|
|
|
"error": job.get("error", None),
|
|
|
|
}
|
|
|
|
for jobid, job in ApiBG.jobs.items()
|
|
|
|
]
|
2024-05-12 07:12:53 +00:00
|
|
|
|
|
|
|
|
2024-05-12 14:51:11 +00:00
|
|
|
@router.get("/background/{jobid}", response_model=BackgroundTaskStatus, tags=["webserver"])
|
2023-06-01 18:40:12 +00:00
|
|
|
def background_job(jobid: str):
|
|
|
|
if not (job := ApiBG.jobs.get(jobid)):
|
2024-05-12 14:51:11 +00:00
|
|
|
raise HTTPException(status_code=404, detail="Job not found.")
|
2023-06-01 18:40:12 +00:00
|
|
|
|
|
|
|
return {
|
2024-05-12 14:51:11 +00:00
|
|
|
"job_id": jobid,
|
|
|
|
"job_category": job["category"],
|
|
|
|
"status": job["status"],
|
|
|
|
"running": job["is_running"],
|
|
|
|
"progress": job.get("progress"),
|
|
|
|
"error": job.get("error", None),
|
2023-06-01 18:40:12 +00:00
|
|
|
}
|