Archive old reference IDs
This commit is contained in:
parent
b1fa6182ef
commit
be46f79ef7
|
@ -99,6 +99,7 @@ class Agora(object):
|
|||
for ref in list(self.last_dash): # We're removing from the list on the fly
|
||||
if ref not in current_trades:
|
||||
self.last_dash.remove(ref)
|
||||
self.tx.cleanup(current_trades)
|
||||
return dash_tmp
|
||||
|
||||
def dashboard_release_urls(self):
|
||||
|
|
|
@ -163,6 +163,19 @@ class Transactions(object):
|
|||
references.append(r.get(key))
|
||||
return convert(references)
|
||||
|
||||
def get_ref_map(self):
|
||||
"""
|
||||
Get all reference IDs for trades.
|
||||
:return: dict of references keyed by TXID
|
||||
:rtype: dict
|
||||
"""
|
||||
references = {}
|
||||
ref_keys = r.keys("trade.*.reference")
|
||||
for key in ref_keys:
|
||||
tx = convert(key).split(".")[1]
|
||||
references[tx] = r.get(key)
|
||||
return convert(references)
|
||||
|
||||
def get_ref(self, reference):
|
||||
"""
|
||||
Get a reference ID for a single trade.
|
||||
|
@ -178,8 +191,16 @@ class Transactions(object):
|
|||
"""
|
||||
Delete a given reference from the Redis database.
|
||||
"""
|
||||
tx = self.ref_to_tx(reference)
|
||||
r.delete(f"trade.{reference}")
|
||||
r.delete(f"trade.{reference}.reference")
|
||||
r.delete(f"trade.{tx}.reference")
|
||||
|
||||
def cleanup(self, references):
|
||||
for tx, reference in self.get_ref_map().items():
|
||||
if reference not in references:
|
||||
self.log.info("Archiving trade reference: {reference} / TX: {tx}", reference=reference, tx=tx)
|
||||
r.rename(f"trade.{tx}.reference", f"archive.trade.{tx}.reference")
|
||||
r.rename(f"trade.{reference}", f"archive.trade.{reference}")
|
||||
|
||||
def del_tx(self, txid):
|
||||
pass
|
||||
|
|
Loading…
Reference in New Issue