You've already forked transaction-tracker
fix(tracker): is_processed now checks expires_at, not just file existence 🐛
Previously is_processed() returned True for any record file that existed, relying entirely on cleanup_expired() (called at __init__) to delete stale files. Because cleanup runs at container startup — before Akahu transactions are fetched — any record that expired exactly on that startup would be deleted and then immediately missed, letting the duplicate through. Fix: is_processed() reads the expires_at field from the JSON and returns False if the record has expired, regardless of whether cleanup has run. Also adds migrate_ttl.py script to retroactively extend expires_at on existing records that were written under a shorter TTL, and bumps version to 0.1.3.
This commit is contained in:
@@ -40,9 +40,17 @@ class TransactionTracker:
|
||||
self.logger.debug(f"Transaction {transaction_id} marked as processed")
|
||||
|
||||
def is_processed(self, transaction_id):
|
||||
"""Check if transaction was already processed."""
|
||||
"""Check if transaction was already processed and its record has not expired."""
|
||||
record_path = os.path.join(self.storage_dir, f"{transaction_id}.json")
|
||||
return os.path.exists(record_path)
|
||||
if not os.path.exists(record_path):
|
||||
return False
|
||||
try:
|
||||
with open(record_path, "r") as f:
|
||||
record = json.load(f)
|
||||
expires_at = datetime.fromisoformat(record["expires_at"])
|
||||
return datetime.now() < expires_at
|
||||
except (json.JSONDecodeError, KeyError, ValueError, TypeError):
|
||||
return False
|
||||
|
||||
def require_unique_transaction(self, id_arg='transaction_id'):
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user