mirror of
https://github.com/RoboSats/robosats.git
synced 2024-12-14 11:26:24 +00:00
Create task to delete canceled LNpayments older than 3 days
This commit is contained in:
parent
8b7e05a24d
commit
6fa145c185
38
api/tasks.py
38
api/tasks.py
@ -162,6 +162,44 @@ def follow_send_payment(hash):
|
|||||||
context = {"routing_failed": "The payout invoice has expired"}
|
context = {"routing_failed": "The payout invoice has expired"}
|
||||||
return False, context
|
return False, context
|
||||||
|
|
||||||
|
@shared_task(name="lnpayments_cleansing")
|
||||||
|
def lnpayments_cleansing():
|
||||||
|
"""
|
||||||
|
Deletes cancelled lnpayments (hodl invoices never locked) that
|
||||||
|
belong to orders expired more than 3 days ago
|
||||||
|
"""
|
||||||
|
|
||||||
|
from django.db.models import Q
|
||||||
|
from api.models import LNPayment
|
||||||
|
from datetime import timedelta
|
||||||
|
from django.utils import timezone
|
||||||
|
|
||||||
|
# Orders that have expired more than -3 days ago
|
||||||
|
# Usually expiry is 1 day for every finished order. So ~4 days until
|
||||||
|
# a never locked hodl invoice is removed.
|
||||||
|
finished_time = timezone.now() - timedelta(days=3)
|
||||||
|
queryset = LNPayment.objects.filter(Q(status=LNPayment.Status.CANCEL),
|
||||||
|
Q(order_made__expires_at__lt=finished_time)|
|
||||||
|
Q(order_taken__expires_at__lt=finished_time))
|
||||||
|
|
||||||
|
|
||||||
|
# And do not have an active trade, any past contract or any reward.
|
||||||
|
deleted_lnpayments = []
|
||||||
|
for lnpayment in queryset:
|
||||||
|
# Try an except. In case some chatroom is already missing.
|
||||||
|
try:
|
||||||
|
name = str(lnpayment)
|
||||||
|
lnpayment.delete()
|
||||||
|
deleted_lnpayments.append(name)
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
|
||||||
|
results = {
|
||||||
|
"num_deleted": len(deleted_lnpayments),
|
||||||
|
"deleted_lnpayments": deleted_lnpayments,
|
||||||
|
}
|
||||||
|
return results
|
||||||
|
|
||||||
@shared_task(name="cache_external_market_prices", ignore_result=True)
|
@shared_task(name="cache_external_market_prices", ignore_result=True)
|
||||||
def cache_market():
|
def cache_market():
|
||||||
|
|
||||||
|
@ -39,6 +39,10 @@ app.conf.beat_schedule = {
|
|||||||
"task": "chatrooms_cleansing",
|
"task": "chatrooms_cleansing",
|
||||||
"schedule": crontab(hour=0, minute=0),
|
"schedule": crontab(hour=0, minute=0),
|
||||||
},
|
},
|
||||||
|
"lnpayments-cleansing": { # Cleans 3+ days old unlocked hodl invoices
|
||||||
|
"task": "lnpayments_cleansing",
|
||||||
|
"schedule": crontab(hour=0, minute=0),
|
||||||
|
},
|
||||||
"give-rewards": { # Referral rewards go from 'pending' to 'earned' at midnight
|
"give-rewards": { # Referral rewards go from 'pending' to 'earned' at midnight
|
||||||
"task": "give_rewards",
|
"task": "give_rewards",
|
||||||
"schedule": crontab(hour=0, minute=0),
|
"schedule": crontab(hour=0, minute=0),
|
||||||
|
Loading…
Reference in New Issue
Block a user