summary: close the db when the lightningd will stop.

Signed-off-by: Vincenzo Palazzo <vincenzopalazzodev@gmail.com>
This commit is contained in:
Vincenzo Palazzo
2021-12-05 15:33:33 +01:00
committed by Christian Decker
parent a6829450db
commit 22923724a9

View File

@@ -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',