Commit 33e57f53 authored by David Seaward's avatar David Seaward
Browse files

Log exceptions when deleting pending users.


Signed-off-by: David Seaward's avatarDavid Seaward <david.seaward@puri.sm>
parent cc0d1022
Pipeline #54243 passed with stage
in 30 seconds
from celery.utils.log import get_task_logger
from django.utils import timezone
from cart.models import ChosenReward
from ldapregister.models import LdapPerson
from limitmonitor.common import active_subscription
logger = get_task_logger(__name__)
def purge_users_pending_cart():
pending_carts = ChosenReward.objects.filter(is_pending=True)
now = timezone.now()
for pending_cart in pending_carts:
# Get User and username
user = pending_cart.user
username = user.username
date_joined = user.date_joined
time_pending = now - date_joined
sub = active_subscription(user)
paid = sub is not None
if time_pending.total_seconds() > 60 * 60 * 24 and not paid:
# Delete Ldap entry
ldap_user = LdapPerson.objects.filter(uid=username)
ldap_user.delete()
# Delete WooCommerce account
user.delete_woocommerce_account()
# Finally delete user
user.delete()
try:
# Get User and username
user = pending_cart.user
username = user.username
date_joined = user.date_joined
time_pending = now - date_joined
sub = active_subscription(user)
paid = sub is not None
if time_pending.total_seconds() > 60 * 60 * 24 and not paid:
# Delete LDAP entry
try:
ldap_user = LdapPerson.objects.filter(uid=username)
ldap_user.delete()
except Exception as e:
logger.exception("Could not delete user {} from LDAP.".format(username))
# Delete WooCommerce account
try:
user.delete_woocommerce_account()
except Exception as e:
logger.exception("Could not delete user {} from WooCommerce.".format(username))
# Finally delete user
try:
user.delete()
except Exception as e:
logger.exception("Could not delete user {} from Django.".format(username))
except Exception as e:
logger.exception("Could not delete pending user {}.".format(username))
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment