Merge pull request #8245 from eSAMTrade/bugfix-8244

Fix last_process related bug in RPC.health (BUG-#8231)
This commit is contained in:
Matthias 2023-02-28 18:18:53 +01:00 committed by GitHub
commit 5660036f47
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 21 additions and 14 deletions

View File

@ -127,7 +127,7 @@ class FreqtradeBot(LoggingMixin):
for minutes in [0, 15, 30, 45]: for minutes in [0, 15, 30, 45]:
t = str(time(time_slot, minutes, 2)) t = str(time(time_slot, minutes, 2))
self._schedule.every().day.at(t).do(update) self._schedule.every().day.at(t).do(update)
self.last_process = datetime(1970, 1, 1, tzinfo=timezone.utc) self.last_process: Optional[datetime] = None
self.strategy.ft_bot_start() self.strategy.ft_bot_start()
# Initialize protections AFTER bot start - otherwise parameters are not loaded. # Initialize protections AFTER bot start - otherwise parameters are not loaded.

View File

@ -457,5 +457,5 @@ class SysInfo(BaseModel):
class Health(BaseModel): class Health(BaseModel):
last_process: datetime last_process: Optional[datetime]
last_process_ts: int last_process_ts: Optional[int]

View File

@ -346,4 +346,4 @@ def sysinfo():
@router.get('/health', response_model=Health, tags=['info']) @router.get('/health', response_model=Health, tags=['info'])
def health(rpc: RPC = Depends(get_rpc)): def health(rpc: RPC = Depends(get_rpc)):
return rpc._health() return rpc.health()

View File

@ -1198,12 +1198,19 @@ class RPC:
"ram_pct": psutil.virtual_memory().percent "ram_pct": psutil.virtual_memory().percent
} }
def _health(self) -> Dict[str, Union[str, int]]: def health(self) -> Dict[str, Optional[Union[str, int]]]:
last_p = self._freqtrade.last_process last_p = self._freqtrade.last_process
if last_p is None:
return { return {
'last_process': str(last_p), "last_process": None,
'last_process_loc': last_p.astimezone(tzlocal()).strftime(DATETIME_PRINT_FORMAT), "last_process_loc": None,
'last_process_ts': int(last_p.timestamp()), "last_process_ts": None,
}
return {
"last_process": str(last_p),
"last_process_loc": last_p.astimezone(tzlocal()).strftime(DATETIME_PRINT_FORMAT),
"last_process_ts": int(last_p.timestamp()),
} }
def _update_market_direction(self, direction: MarketDirection) -> None: def _update_market_direction(self, direction: MarketDirection) -> None:

View File

@ -1540,7 +1540,7 @@ class Telegram(RPCHandler):
Handler for /health Handler for /health
Shows the last process timestamp Shows the last process timestamp
""" """
health = self._rpc._health() health = self._rpc.health()
message = f"Last process: `{health['last_process_loc']}`" message = f"Last process: `{health['last_process_loc']}`"
self._send_msg(message) self._send_msg(message)

View File

@ -1252,6 +1252,6 @@ def test_rpc_health(mocker, default_conf) -> None:
freqtradebot = get_patched_freqtradebot(mocker, default_conf) freqtradebot = get_patched_freqtradebot(mocker, default_conf)
rpc = RPC(freqtradebot) rpc = RPC(freqtradebot)
result = rpc._health() result = rpc.health()
assert result['last_process'] == '1970-01-01 00:00:00+00:00' assert result['last_process'] is None
assert result['last_process_ts'] == 0 assert result['last_process_ts'] is None

View File

@ -1803,8 +1803,8 @@ def test_health(botclient):
assert_response(rc) assert_response(rc)
ret = rc.json() ret = rc.json()
assert ret['last_process_ts'] == 0 assert ret["last_process_ts"] is None
assert ret['last_process'] == '1970-01-01T00:00:00+00:00' assert ret["last_process"] is None
def test_api_ws_subscribe(botclient, mocker): def test_api_ws_subscribe(botclient, mocker):