mirror of
https://github.com/freqtrade/freqtrade.git
synced 2024-11-10 10:21:59 +00:00
Slightly extend background jobs api
This commit is contained in:
parent
0279cf5fed
commit
e4881580fd
|
@ -1,5 +1,6 @@
|
|||
import logging
|
||||
from copy import deepcopy
|
||||
from typing import List
|
||||
|
||||
from fastapi import APIRouter, BackgroundTasks, Depends
|
||||
from fastapi.exceptions import HTTPException
|
||||
|
@ -21,6 +22,19 @@ logger = logging.getLogger(__name__)
|
|||
router = APIRouter()
|
||||
|
||||
|
||||
@router.get('/background', response_model=List[BackgroundTaskStatus], tags=['webserver'])
|
||||
def background_job_list():
|
||||
|
||||
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()]
|
||||
|
||||
|
||||
@router.get('/background/{jobid}', response_model=BackgroundTaskStatus, tags=['webserver'])
|
||||
def background_job(jobid: str):
|
||||
if not (job := ApiBG.jobs.get(jobid)):
|
||||
|
@ -32,7 +46,7 @@ def background_job(jobid: str):
|
|||
'status': job['status'],
|
||||
'running': job['is_running'],
|
||||
'progress': job.get('progress'),
|
||||
# 'job_error': job['error'],
|
||||
'error': job.get('error', None),
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -44,6 +44,7 @@ class BackgroundTaskStatus(BaseModel):
|
|||
status: str
|
||||
running: bool
|
||||
progress: Optional[float] = None
|
||||
error: Optional[str] = None
|
||||
|
||||
|
||||
class BackgroundTaskResult(BaseModel):
|
||||
|
|
|
@ -1964,6 +1964,15 @@ def test_api_pairlists_evaluate(botclient, tmp_path, mocker):
|
|||
assert_response(rc, 404)
|
||||
assert rc.json()['detail'] == 'Job not found.'
|
||||
|
||||
# Background list
|
||||
rc = client_get(client, f"{BASE_URI}/background")
|
||||
assert_response(rc)
|
||||
response = rc.json()
|
||||
assert isinstance(response, list)
|
||||
assert len(response) == 1
|
||||
assert response[0]['job_id'] == job_id
|
||||
|
||||
# Get individual job
|
||||
rc = client_get(client, f"{BASE_URI}/background/{job_id}")
|
||||
assert_response(rc)
|
||||
response = rc.json()
|
||||
|
|
Loading…
Reference in New Issue
Block a user