mirror of
https://github.com/RoboSats/robosats.git
synced 2025-07-17 16:23:13 +00:00
Create task to delete older than 3 days encrypted messages
This commit is contained in:
@ -94,7 +94,7 @@ class Logics:
|
|||||||
''' Validates PGP valid keys. Formats them in a way understandable by the frontend '''
|
''' Validates PGP valid keys. Formats them in a way understandable by the frontend '''
|
||||||
gpg = gnupg.GPG()
|
gpg = gnupg.GPG()
|
||||||
|
|
||||||
# Uniform format as linux linebreaks. Windows users submitting their own keys have \r\n breaks.
|
# Standarize format with linux linebreaks '\n'. Windows users submitting their own keys have '\r\n' breaking communication.
|
||||||
enc_priv_key = enc_priv_key.replace('\r\n', '\n')
|
enc_priv_key = enc_priv_key.replace('\r\n', '\n')
|
||||||
pub_key = pub_key.replace('\r\n', '\n')
|
pub_key = pub_key.replace('\r\n', '\n')
|
||||||
|
|
||||||
|
@ -396,11 +396,11 @@ class Order(models.Model):
|
|||||||
11: 1 * 24 * 60 * 60, # 'In dispute'
|
11: 1 * 24 * 60 * 60, # 'In dispute'
|
||||||
12: 0, # 'Collaboratively cancelled'
|
12: 0, # 'Collaboratively cancelled'
|
||||||
13: 10 * 24 * 60 * 60, # 'Sending satoshis to buyer'
|
13: 10 * 24 * 60 * 60, # 'Sending satoshis to buyer'
|
||||||
14: 10 * 24 * 60 * 60, # 'Sucessful trade'
|
14: 1 * 24 * 60 * 60, # 'Sucessful trade'
|
||||||
15: 10 * 24 * 60 * 60, # 'Failed lightning network routing'
|
15: 10 * 24 * 60 * 60, # 'Failed lightning network routing'
|
||||||
16: 10 * 24 * 60 * 60, # 'Wait for dispute resolution'
|
16: 10 * 24 * 60 * 60, # 'Wait for dispute resolution'
|
||||||
17: 10 * 24 * 60 * 60, # 'Maker lost dispute'
|
17: 1 * 24 * 60 * 60, # 'Maker lost dispute'
|
||||||
18: 10 * 24 * 60 * 60, # 'Taker lost dispute'
|
18: 1 * 24 * 60 * 60, # 'Taker lost dispute'
|
||||||
}
|
}
|
||||||
|
|
||||||
return t_to_expire[status]
|
return t_to_expire[status]
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
from celery import shared_task
|
from celery import shared_task
|
||||||
|
|
||||||
|
|
||||||
@shared_task(name="users_cleansing")
|
@shared_task(name="users_cleansing")
|
||||||
def users_cleansing():
|
def users_cleansing():
|
||||||
"""
|
"""
|
||||||
@ -8,7 +7,7 @@ def users_cleansing():
|
|||||||
"""
|
"""
|
||||||
from django.contrib.auth.models import User
|
from django.contrib.auth.models import User
|
||||||
from django.db.models import Q
|
from django.db.models import Q
|
||||||
from .logics import Logics
|
from api.logics import Logics
|
||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
from django.utils import timezone
|
from django.utils import timezone
|
||||||
|
|
||||||
@ -163,7 +162,6 @@ 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="cache_external_market_prices", ignore_result=True)
|
@shared_task(name="cache_external_market_prices", ignore_result=True)
|
||||||
def cache_market():
|
def cache_market():
|
||||||
|
|
||||||
|
42
chat/tasks.py
Normal file
42
chat/tasks.py
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
from celery import shared_task
|
||||||
|
|
||||||
|
@shared_task(name="chatrooms_cleansing")
|
||||||
|
def chatrooms_cleansing():
|
||||||
|
"""
|
||||||
|
Deletes chatrooms and encrypted messages of orders
|
||||||
|
that have completely finished more than 3 days ago.
|
||||||
|
"""
|
||||||
|
|
||||||
|
from api.models import Order
|
||||||
|
from chat.models import ChatRoom
|
||||||
|
from datetime import timedelta
|
||||||
|
from django.utils import timezone
|
||||||
|
|
||||||
|
finished_states = [Order.Status.SUC,
|
||||||
|
Order.Status.TLD,
|
||||||
|
Order.Status.MLD,
|
||||||
|
Order.Status.CCA,
|
||||||
|
Order.Status.UCA]
|
||||||
|
|
||||||
|
# Orders that have expired more than 3 days ago
|
||||||
|
# Usually expiry takes place 1 day after a finished order. So, ~4 days
|
||||||
|
# until encrypted messages are deleted.
|
||||||
|
finished_time = timezone.now() - timedelta(days=3)
|
||||||
|
queryset = Order.objects.filter(status__in=finished_states, expires_at__lt=finished_time)
|
||||||
|
|
||||||
|
# And do not have an active trade, any past contract or any reward.
|
||||||
|
deleted_chatrooms = []
|
||||||
|
for order in queryset:
|
||||||
|
# Try an except. In case some chatroom is already missing.
|
||||||
|
try:
|
||||||
|
chatroom = ChatRoom.objects.get(id = order.id)
|
||||||
|
deleted_chatrooms.append(str(chatroom))
|
||||||
|
chatroom.delete()
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
|
||||||
|
results = {
|
||||||
|
"num_deleted": len(deleted_chatrooms),
|
||||||
|
"deleted_chatrooms": deleted_chatrooms,
|
||||||
|
}
|
||||||
|
return results
|
@ -35,13 +35,17 @@ app.conf.beat_schedule = {
|
|||||||
"task": "users_cleansing",
|
"task": "users_cleansing",
|
||||||
"schedule": crontab(hour=0, minute=0),
|
"schedule": crontab(hour=0, minute=0),
|
||||||
},
|
},
|
||||||
|
"chatrooms-cleansing": { # Cleans 3+ days old encrypted messages and chatrooms at midnight
|
||||||
|
"task": "chatrooms_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),
|
||||||
},
|
},
|
||||||
"do-accounting": { # Does accounting for the last day
|
"do-accounting": { # Does accounting for the last day
|
||||||
"task": "do_accounting",
|
"task": "do_accounting",
|
||||||
"schedule": crontab(hour=23, minute=55),
|
"schedule": crontab(hour=23, minute=59),
|
||||||
},
|
},
|
||||||
"cache-market-prices": { # Cache market prices every minute
|
"cache-market-prices": { # Cache market prices every minute
|
||||||
"task": "cache_external_market_prices",
|
"task": "cache_external_market_prices",
|
||||||
|
Reference in New Issue
Block a user