mirror of
https://github.com/aljazceru/plugins.git
synced 2025-12-23 16:14:20 +01:00
summary: close the db when the lightningd will stop.
Signed-off-by: Vincenzo Palazzo <vincenzopalazzodev@gmail.com>
This commit is contained in:
committed by
Christian Decker
parent
a6829450db
commit
22923724a9
@@ -10,6 +10,7 @@ import threading
|
|||||||
import time
|
import time
|
||||||
import os
|
import os
|
||||||
import glob
|
import glob
|
||||||
|
import sys
|
||||||
|
|
||||||
|
|
||||||
plugin = Plugin(autopatch=True)
|
plugin = Plugin(autopatch=True)
|
||||||
@@ -268,6 +269,23 @@ def init_db(plugin, retry_time=4, sleep_time=1):
|
|||||||
return db
|
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()
|
@plugin.init()
|
||||||
def init(options, configuration, plugin):
|
def init(options, configuration, plugin):
|
||||||
plugin.currency = options['summary-currency']
|
plugin.currency = options['summary-currency']
|
||||||
@@ -320,6 +338,13 @@ def init(options, configuration, plugin):
|
|||||||
plugin.log("Plugin summary.py initialized")
|
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(
|
plugin.add_option(
|
||||||
'summary-currency',
|
'summary-currency',
|
||||||
'USD',
|
'USD',
|
||||||
|
|||||||
Reference in New Issue
Block a user