Move heartbeat to worker
This commit is contained in:
		| @@ -6,7 +6,6 @@ import logging | ||||
| import traceback | ||||
| from datetime import datetime | ||||
| from math import isclose | ||||
| from os import getpid | ||||
| from threading import Lock | ||||
| from typing import Any, Dict, List, Optional, Tuple | ||||
|  | ||||
| @@ -52,10 +51,6 @@ class FreqtradeBot: | ||||
|         # Init objects | ||||
|         self.config = config | ||||
|  | ||||
|         self._heartbeat_msg = 0 | ||||
|  | ||||
|         self.heartbeat_interval = self.config.get('internals', {}).get('heartbeat_interval', 60) | ||||
|  | ||||
|         self.strategy: IStrategy = StrategyResolver.load_strategy(self.config) | ||||
|  | ||||
|         # Check config consistency here since strategies can set certain options | ||||
| @@ -159,11 +154,6 @@ class FreqtradeBot: | ||||
|         self.check_handle_timedout() | ||||
|         Trade.session.flush() | ||||
|  | ||||
|         if (self.heartbeat_interval | ||||
|                 and (arrow.utcnow().timestamp - self._heartbeat_msg > self.heartbeat_interval)): | ||||
|             logger.info(f"Bot heartbeat. PID={getpid()}") | ||||
|             self._heartbeat_msg = arrow.utcnow().timestamp | ||||
|  | ||||
|     def _refresh_whitelist(self, trades: List[Trade] = []) -> List[str]: | ||||
|         """ | ||||
|         Refresh whitelist from pairlist or edge and extend it with trades. | ||||
|   | ||||
| @@ -4,8 +4,10 @@ Main Freqtrade worker class. | ||||
| import logging | ||||
| import time | ||||
| import traceback | ||||
| from os import getpid | ||||
| from typing import Any, Callable, Dict, Optional | ||||
|  | ||||
| import arrow | ||||
| import sdnotify | ||||
|  | ||||
| from freqtrade import __version__, constants | ||||
| @@ -33,6 +35,7 @@ class Worker: | ||||
|         self._init(False) | ||||
|  | ||||
|         self.last_throttle_start_time: Optional[float] = None | ||||
|         self._heartbeat_msg = 0 | ||||
|  | ||||
|         # Tell systemd that we completed initialization phase | ||||
|         if self._sd_notify: | ||||
| @@ -50,10 +53,10 @@ class Worker: | ||||
|         # Init the instance of the bot | ||||
|         self.freqtrade = FreqtradeBot(self._config) | ||||
|  | ||||
|         self._throttle_secs = self._config.get('internals', {}).get( | ||||
|             'process_throttle_secs', | ||||
|             constants.PROCESS_THROTTLE_SECS | ||||
|         ) | ||||
|         internals_config = self._config.get('internals', {}) | ||||
|         self._throttle_secs = internals_config.get('process_throttle_secs', | ||||
|                                                    constants.PROCESS_THROTTLE_SECS) | ||||
|         self._heartbeat_interval = internals_config.get('heartbeat_interval', 60) | ||||
|  | ||||
|         self._sd_notify = sdnotify.SystemdNotifier() if \ | ||||
|             self._config.get('internals', {}).get('sd_notify', False) else None | ||||
| @@ -97,6 +100,11 @@ class Worker: | ||||
|  | ||||
|             self._throttle(func=self._process_running, throttle_secs=self._throttle_secs) | ||||
|  | ||||
|         if (self._heartbeat_interval | ||||
|                 and (arrow.utcnow().timestamp - self._heartbeat_msg > self._heartbeat_interval)): | ||||
|             logger.info(f"Bot heartbeat. PID={getpid()}") | ||||
|             self._heartbeat_msg = arrow.utcnow().timestamp | ||||
|  | ||||
|         return state | ||||
|  | ||||
|     def _throttle(self, func: Callable[..., Any], throttle_secs: float, *args, **kwargs) -> Any: | ||||
|   | ||||
		Reference in New Issue
	
	Block a user