code cleanup; added message to systemd for reconfiguration

This commit is contained in:
hroff-1902 2019-03-11 13:14:55 +03:00
parent 8730852d6e
commit 41add9f8ca
2 changed files with 18 additions and 8 deletions

View File

@ -84,7 +84,7 @@ class FreqtradeBot(object):
# Tell the systemd that we completed initialization phase # Tell the systemd that we completed initialization phase
if self._sd_notify: if self._sd_notify:
logger.debug("sd_notify: READY=1") logger.debug("sd_notify: READY=1")
self._sd_notify.notify('READY=1') self._sd_notify.notify("READY=1")
def _init_modules(self) -> None: def _init_modules(self) -> None:
""" """
@ -110,14 +110,21 @@ class FreqtradeBot(object):
""" """
logger.info('Cleaning up modules ...') logger.info('Cleaning up modules ...')
# Tell systemd that we are stopping now
if self._sd_notify:
logger.debug("sd_notify: STOPPING=1")
self._sd_notify.notify('STOPPING=1')
self.rpc.cleanup() self.rpc.cleanup()
persistence.cleanup() persistence.cleanup()
def stopping(self) -> None:
# Tell systemd that we are exiting now
if self._sd_notify:
logger.debug("sd_notify: STOPPING=1")
self._sd_notify.notify("STOPPING=1")
def reconfigure(self) -> None:
# Tell systemd that we initiated reconfiguring
if self._sd_notify:
logger.debug("sd_notify: RELOADING=1")
self._sd_notify.notify("RELOADING=1")
def worker(self, old_state: State = None) -> State: def worker(self, old_state: State = None) -> State:
""" """
Trading routine that must be run at each loop Trading routine that must be run at each loop
@ -144,7 +151,7 @@ class FreqtradeBot(object):
# Ping systemd watchdog before sleeping in the stopped state # Ping systemd watchdog before sleeping in the stopped state
if self._sd_notify: if self._sd_notify:
logger.debug("sd_notify: WATCHDOG=1\\nSTATUS=State: STOPPED.") logger.debug("sd_notify: WATCHDOG=1\\nSTATUS=State: STOPPED.")
self._sd_notify.notify('WATCHDOG=1\nSTATUS=State: STOPPED.') self._sd_notify.notify("WATCHDOG=1\nSTATUS=State: STOPPED.")
time.sleep(throttle_secs) time.sleep(throttle_secs)
@ -152,7 +159,7 @@ class FreqtradeBot(object):
# Ping systemd watchdog before throttling # Ping systemd watchdog before throttling
if self._sd_notify: if self._sd_notify:
logger.debug("sd_notify: WATCHDOG=1\\nSTATUS=State: RUNNING.") logger.debug("sd_notify: WATCHDOG=1\\nSTATUS=State: RUNNING.")
self._sd_notify.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, min_secs=throttle_secs)

View File

@ -60,6 +60,7 @@ def main(sysargv: List[str]) -> None:
logger.exception('Fatal exception!') logger.exception('Fatal exception!')
finally: finally:
if freqtrade: if freqtrade:
freqtrade.stopping()
freqtrade.rpc.send_msg({ freqtrade.rpc.send_msg({
'type': RPCMessageType.STATUS_NOTIFICATION, 'type': RPCMessageType.STATUS_NOTIFICATION,
'status': 'process died' 'status': 'process died'
@ -72,6 +73,8 @@ def reconfigure(freqtrade: FreqtradeBot, args: Namespace) -> FreqtradeBot:
""" """
Cleans up current instance, reloads the configuration and returns the new instance Cleans up current instance, reloads the configuration and returns the new instance
""" """
freqtrade.reconfigure()
# Clean up current modules # Clean up current modules
freqtrade.cleanup() freqtrade.cleanup()