Skip to content

Commit

Permalink
Use _throttle() in stopped state instead of sleep()
Browse files Browse the repository at this point in the history
  • Loading branch information
hroff-1902 committed Feb 20, 2020
1 parent 56a06cb commit 78ee36a
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions freqtrade/worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,15 +87,15 @@ def _worker(self, old_state: Optional[State], throttle_secs: Optional[float] = N
logger.debug("sd_notify: WATCHDOG=1\\nSTATUS=State: STOPPED.")
self._sd_notify.notify("WATCHDOG=1\nSTATUS=State: STOPPED.")

time.sleep(throttle_secs)
self._throttle(func=self._process_stopped, min_secs=throttle_secs)

elif state == State.RUNNING:
# Ping systemd watchdog before throttling
if self._sd_notify:
logger.debug("sd_notify: WATCHDOG=1\\nSTATUS=State: RUNNING.")
self._sd_notify.notify("WATCHDOG=1\nSTATUS=State: RUNNING.")

self._throttle(func=self._process, min_secs=throttle_secs)
self._throttle(func=self._process_running, min_secs=throttle_secs)

return state

Expand All @@ -116,7 +116,11 @@ def _throttle(self, func: Callable[..., Any], min_secs: float, *args, **kwargs)
time.sleep(duration)
return result

def _process(self) -> None:
def _process_stopped(self) -> None:
# Maybe do here something in the future...
pass

def _process_running(self) -> None:
try:
self.freqtrade.process()
except TemporaryError as error:
Expand Down

0 comments on commit 78ee36a

Please sign in to comment.