feat: api progressbar handling
This commit is contained in:
@@ -11,6 +11,7 @@ from freqtrade.rpc.api_server.api_pairlists import handleExchangePayload
|
|||||||
from freqtrade.rpc.api_server.api_schemas import BgJobStarted, DownloadDataPayload
|
from freqtrade.rpc.api_server.api_schemas import BgJobStarted, DownloadDataPayload
|
||||||
from freqtrade.rpc.api_server.deps import get_config, get_exchange
|
from freqtrade.rpc.api_server.deps import get_config, get_exchange
|
||||||
from freqtrade.rpc.api_server.webserver_bgwork import ApiBG
|
from freqtrade.rpc.api_server.webserver_bgwork import ApiBG
|
||||||
|
from freqtrade.util.progress_tracker import get_progress_tracker
|
||||||
|
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
@@ -27,7 +28,12 @@ def __run_download(job_id: str, config_loc: Config):
|
|||||||
with FtNoDBContext():
|
with FtNoDBContext():
|
||||||
exchange = get_exchange(config_loc)
|
exchange = get_exchange(config_loc)
|
||||||
|
|
||||||
download_data(config_loc, exchange)
|
def ft_callback(task) -> None:
|
||||||
|
print(task)
|
||||||
|
|
||||||
|
pt = get_progress_tracker(ft_callback=ft_callback)
|
||||||
|
|
||||||
|
download_data(config_loc, exchange, progress_tracker=pt)
|
||||||
# ApiBG.jobs[job_id]["result"] = {
|
# ApiBG.jobs[job_id]["result"] = {
|
||||||
|
|
||||||
# }
|
# }
|
||||||
|
|||||||
@@ -1,7 +1,8 @@
|
|||||||
from collections.abc import Callable
|
from collections.abc import Callable
|
||||||
|
from typing import Any
|
||||||
|
|
||||||
from rich.console import ConsoleRenderable, Group, RichCast
|
from rich.console import ConsoleRenderable, Group, RichCast
|
||||||
from rich.progress import Progress
|
from rich.progress import Progress, Task, TaskID
|
||||||
|
|
||||||
|
|
||||||
class CustomProgress(Progress):
|
class CustomProgress(Progress):
|
||||||
@@ -10,13 +11,44 @@ class CustomProgress(Progress):
|
|||||||
*args,
|
*args,
|
||||||
cust_objs: list[ConsoleRenderable] | None = None,
|
cust_objs: list[ConsoleRenderable] | None = None,
|
||||||
cust_callables: list[Callable[[], ConsoleRenderable]] | None = None,
|
cust_callables: list[Callable[[], ConsoleRenderable]] | None = None,
|
||||||
|
ft_callback: Callable[[Task], None] | None = None,
|
||||||
**kwargs,
|
**kwargs,
|
||||||
) -> None:
|
) -> None:
|
||||||
self._cust_objs = cust_objs or []
|
self._cust_objs = cust_objs or []
|
||||||
self._cust_callables = cust_callables or []
|
self._cust_callables = cust_callables or []
|
||||||
|
self._ft_callback = ft_callback
|
||||||
|
if self._ft_callback:
|
||||||
|
kwargs["disable"] = True
|
||||||
|
|
||||||
super().__init__(*args, **kwargs)
|
super().__init__(*args, **kwargs)
|
||||||
|
|
||||||
|
def update(
|
||||||
|
self,
|
||||||
|
task_id: TaskID,
|
||||||
|
*,
|
||||||
|
total: float | None = None,
|
||||||
|
completed: float | None = None,
|
||||||
|
advance: float | None = None,
|
||||||
|
description: str | None = None,
|
||||||
|
visible: bool | None = None,
|
||||||
|
refresh: bool = False,
|
||||||
|
**fields: Any,
|
||||||
|
) -> None:
|
||||||
|
if self._ft_callback:
|
||||||
|
self._ft_callback(
|
||||||
|
self.tasks[task_id],
|
||||||
|
)
|
||||||
|
return super().update(
|
||||||
|
task_id,
|
||||||
|
total=total,
|
||||||
|
completed=completed,
|
||||||
|
advance=advance,
|
||||||
|
description=description,
|
||||||
|
visible=visible,
|
||||||
|
refresh=refresh,
|
||||||
|
**fields,
|
||||||
|
)
|
||||||
|
|
||||||
def get_renderable(self) -> ConsoleRenderable | RichCast | str:
|
def get_renderable(self) -> ConsoleRenderable | RichCast | str:
|
||||||
objs = [obj for obj in self._cust_objs]
|
objs = [obj for obj in self._cust_objs]
|
||||||
for cust_call in self._cust_callables:
|
for cust_call in self._cust_callables:
|
||||||
|
|||||||
Reference in New Issue
Block a user