Commit 65797ae4 authored by David Seaward's avatar David Seaward
Browse files

Improve logging when purging pending users.


Signed-off-by: David Seaward's avatarDavid Seaward <david.seaward@puri.sm>
parent 33e57f53
Pipeline #54247 passed with stage
in 31 seconds
...@@ -11,6 +11,8 @@ logger = get_task_logger(__name__) ...@@ -11,6 +11,8 @@ logger = get_task_logger(__name__)
def purge_users_pending_cart(): def purge_users_pending_cart():
pending_carts = ChosenReward.objects.filter(is_pending=True) pending_carts = ChosenReward.objects.filter(is_pending=True)
now = timezone.now() now = timezone.now()
total_pending = len(pending_carts)
count_pending = 0
for pending_cart in pending_carts: for pending_cart in pending_carts:
try: try:
...@@ -24,25 +26,28 @@ def purge_users_pending_cart(): ...@@ -24,25 +26,28 @@ def purge_users_pending_cart():
paid = sub is not None paid = sub is not None
if time_pending.total_seconds() > 60 * 60 * 24 and not paid: if time_pending.total_seconds() > 60 * 60 * 24 and not paid:
count_pending += 1
# Delete LDAP entry # Delete LDAP entry
try: try:
ldap_user = LdapPerson.objects.filter(uid=username) ldap_user = LdapPerson.objects.filter(uid=username)
ldap_user.delete() ldap_user.delete()
except Exception as e: except Exception as e:
logger.exception("Could not delete user {} from LDAP.".format(username)) logger.exception("Could not delete user {} from LDAP.".format(username), e)
# Delete WooCommerce account # Delete WooCommerce account
try: try:
user.delete_woocommerce_account() user.delete_woocommerce_account()
except Exception as e: except Exception as e:
logger.exception("Could not delete user {} from WooCommerce.".format(username)) logger.exception("Could not delete user {} from WooCommerce.".format(username), e)
# Finally delete user # Finally delete user
try: try:
user.delete() user.delete()
except Exception as e: except Exception as e:
logger.exception("Could not delete user {} from Django.".format(username)) logger.exception("Could not delete user {} from Django.".format(username), e)
except Exception as e: except Exception as e:
logger.exception("Could not delete pending user {}.".format(username)) logger.exception("Could not delete pending user {}.".format(username), e)
logger.info("Purged {count} of {total} pending users.".format(count=count_pending, total=total_pending))
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