system: Reload cached swaps on session errors
This commit is contained in:
parent
2a35148a4b
commit
789cd0f6ab
@ -393,6 +393,13 @@ class BasicSwap(BaseApp):
|
|||||||
use_session.remove()
|
use_session.remove()
|
||||||
self.mxDB.release()
|
self.mxDB.release()
|
||||||
|
|
||||||
|
def handleSessionErrors(self, e, session, tag):
|
||||||
|
if self.debug:
|
||||||
|
self.log.error(traceback.format_exc())
|
||||||
|
|
||||||
|
self.log.error(f'Error: {tag} - {e}')
|
||||||
|
session.rollback()
|
||||||
|
|
||||||
def setCoinConnectParams(self, coin):
|
def setCoinConnectParams(self, coin):
|
||||||
# Set anything that does not require the daemon to be running
|
# Set anything that does not require the daemon to be running
|
||||||
chain_client_settings = self.getChainClientSettings(coin)
|
chain_client_settings = self.getChainClientSettings(coin)
|
||||||
@ -1010,6 +1017,7 @@ class BasicSwap(BaseApp):
|
|||||||
def loadFromDB(self):
|
def loadFromDB(self):
|
||||||
self.log.info('Loading data from db')
|
self.log.info('Loading data from db')
|
||||||
self.mxDB.acquire()
|
self.mxDB.acquire()
|
||||||
|
self.swaps_in_progress.clear()
|
||||||
try:
|
try:
|
||||||
session = scoped_session(self.session_factory)
|
session = scoped_session(self.session_factory)
|
||||||
for bid in session.query(Bid):
|
for bid in session.query(Bid):
|
||||||
@ -3741,6 +3749,7 @@ class BasicSwap(BaseApp):
|
|||||||
self.mxDB.acquire()
|
self.mxDB.acquire()
|
||||||
now = int(time.time())
|
now = int(time.time())
|
||||||
session = None
|
session = None
|
||||||
|
reload_in_progress = False
|
||||||
try:
|
try:
|
||||||
session = scoped_session(self.session_factory)
|
session = scoped_session(self.session_factory)
|
||||||
|
|
||||||
@ -3780,12 +3789,18 @@ class BasicSwap(BaseApp):
|
|||||||
session.execute('DELETE FROM actions WHERE trigger_at <= {}'.format(now))
|
session.execute('DELETE FROM actions WHERE trigger_at <= {}'.format(now))
|
||||||
|
|
||||||
session.commit()
|
session.commit()
|
||||||
|
except Exception as ex:
|
||||||
|
self.handleSessionErrors(ex, session, 'checkQueuedActions')
|
||||||
|
reload_in_progress = True
|
||||||
finally:
|
finally:
|
||||||
if session:
|
if session:
|
||||||
session.close()
|
session.close()
|
||||||
session.remove()
|
session.remove()
|
||||||
self.mxDB.release()
|
self.mxDB.release()
|
||||||
|
|
||||||
|
if reload_in_progress:
|
||||||
|
self.loadFromDB()
|
||||||
|
|
||||||
def checkXmrSwaps(self):
|
def checkXmrSwaps(self):
|
||||||
self.mxDB.acquire()
|
self.mxDB.acquire()
|
||||||
now = int(time.time())
|
now = int(time.time())
|
||||||
|
Loading…
Reference in New Issue
Block a user