diff --git a/summary/summary.py b/summary/summary.py index 9f9c7ec..419b112 100755 --- a/summary/summary.py +++ b/summary/summary.py @@ -10,6 +10,7 @@ import threading import time import os import glob +import sys plugin = Plugin(autopatch=True) @@ -268,6 +269,23 @@ def init_db(plugin, retry_time=4, sleep_time=1): return db +def close_db(plugin) -> bool: + """ + This method contains the logic to close the database + and print some error message that can happen. + """ + if plugin.persist is not None: + try: + plugin.persist.close() + plugin.log("Database sync and closed with success") + except ValueError as ex: + plugin.log("An exception occurs during the db closing operation with the following message: {}".format(ex)) + return False + else: + plugin.log("There is no db opened for the plugin") + return True + + @plugin.init() def init(options, configuration, plugin): plugin.currency = options['summary-currency'] @@ -320,6 +338,13 @@ def init(options, configuration, plugin): plugin.log("Plugin summary.py initialized") +@plugin.subscribe("shutdown") +def on_rpc_command_callback(plugin, **kwargs): + plugin.log("Closing db before lightnind exit") + close_db(plugin) + sys.exit() + + plugin.add_option( 'summary-currency', 'USD',