Implement automatic retry for LDAP errors

This commit is contained in:
Jan Dittberner 2020-03-03 14:50:03 +01:00
parent bdcd16b7e7
commit 99c80f5759

View file

@ -14,13 +14,14 @@ from celery.exceptions import Reject
from celery.utils.log import get_task_logger
from django.core.exceptions import ObjectDoesNotExist
from django.db.utils import Error as DjangoDBUtilsError
from ldapentities.models import LdapGroup, LdapUser
_LOGGER = get_task_logger(__name__)
@shared_task
@shared_task(autoretry_for=(DjangoDBUtilsError,), default_retry_delay=10)
def create_ldap_group(groupname, gid, description):
"""
This task creates an :py:class:`LDAP group <ldapentities.models.LdapGroup>`
@ -58,7 +59,7 @@ def create_ldap_group(groupname, gid, description):
}
@shared_task
@shared_task(autoretry_for=(DjangoDBUtilsError,), default_retry_delay=10)
def create_ldap_user(username, uid, gid, gecos, homedir, shell, password):
"""
This task creates an :py:class:`LDAP user <ldapentities.models.LdapUser>`
@ -129,7 +130,7 @@ def create_ldap_user(username, uid, gid, gecos, homedir, shell, password):
}
@shared_task
@shared_task(autoretry_for=(DjangoDBUtilsError,), default_retry_delay=10)
def set_ldap_user_password(username, password):
"""
This task sets the password of an existing :py:class:`LDAP user
@ -156,7 +157,7 @@ def set_ldap_user_password(username, password):
return retval
@shared_task(bind=True)
@shared_task(autoretry_for=(DjangoDBUtilsError,), default_retry_delay=10)
def add_ldap_user_to_group(self, username, groupname):
"""
This task adds the specified user to the given group.
@ -201,7 +202,7 @@ def add_ldap_user_to_group(self, username, groupname):
return retval
@shared_task
@shared_task(autoretry_for=(DjangoDBUtilsError,), default_retry_delay=10)
def remove_ldap_user_from_group(username, groupname):
"""
This task removes the given user from the given group.
@ -239,7 +240,7 @@ def remove_ldap_user_from_group(username, groupname):
return retval
@shared_task
@shared_task(autoretry_for=(DjangoDBUtilsError,), default_retry_delay=10)
def delete_ldap_user(username, *args, **kwargs):
"""
This task deletes the given user.
@ -287,7 +288,7 @@ def delete_ldap_user(username, *args, **kwargs):
return retval
@shared_task
@shared_task(autoretry_for=(DjangoDBUtilsError,), default_retry_delay=10)
def delete_ldap_user_chained(previous_result, *args, **kwargs):
"""
This task deletes the given user.
@ -307,7 +308,7 @@ def delete_ldap_user_chained(previous_result, *args, **kwargs):
return retval
@shared_task
@shared_task(autoretry_for=(DjangoDBUtilsError,), default_retry_delay=10)
def delete_ldap_group_if_empty(groupname):
"""
This task deletes the given group if it is empty.
@ -339,7 +340,7 @@ def delete_ldap_group_if_empty(groupname):
return retval
@shared_task
@shared_task(autoretry_for=(DjangoDBUtilsError,), default_retry_delay=10)
def delete_ldap_group(groupname):
"""
This task deletes the given group.