sources/ldap: prevent error when retrying old system task with no arguments
Signed-off-by: Jens Langhammer <jens.langhammer@beryju.org>
This commit is contained in:
parent
763d3ae76a
commit
8279690a8f
|
@ -1,4 +1,6 @@
|
||||||
"""LDAP Sync tasks"""
|
"""LDAP Sync tasks"""
|
||||||
|
from typing import Optional
|
||||||
|
|
||||||
from django.utils.text import slugify
|
from django.utils.text import slugify
|
||||||
from ldap3.core.exceptions import LDAPException
|
from ldap3.core.exceptions import LDAPException
|
||||||
from structlog.stdlib import get_logger
|
from structlog.stdlib import get_logger
|
||||||
|
@ -29,7 +31,8 @@ def ldap_sync_all():
|
||||||
@CELERY_APP.task(
|
@CELERY_APP.task(
|
||||||
bind=True, base=MonitoredTask, soft_time_limit=60 * 60 * 2, task_time_limit=60 * 60 * 2
|
bind=True, base=MonitoredTask, soft_time_limit=60 * 60 * 2, task_time_limit=60 * 60 * 2
|
||||||
)
|
)
|
||||||
def ldap_sync(self: MonitoredTask, source_pk: str, sync_class: str):
|
# TODO: remove Optional[str] in 2021.10
|
||||||
|
def ldap_sync(self: MonitoredTask, source_pk: str, sync_class: Optional[str] = None):
|
||||||
"""Synchronization of an LDAP Source"""
|
"""Synchronization of an LDAP Source"""
|
||||||
self.result_timeout_hours = 2
|
self.result_timeout_hours = 2
|
||||||
try:
|
try:
|
||||||
|
@ -38,6 +41,8 @@ def ldap_sync(self: MonitoredTask, source_pk: str, sync_class: str):
|
||||||
# Because the source couldn't be found, we don't have a UID
|
# Because the source couldn't be found, we don't have a UID
|
||||||
# to set the state with
|
# to set the state with
|
||||||
return
|
return
|
||||||
|
if not sync_class:
|
||||||
|
return
|
||||||
sync = path_to_class(sync_class)
|
sync = path_to_class(sync_class)
|
||||||
self.set_uid(f"{slugify(source.name)}-{sync.__name__}")
|
self.set_uid(f"{slugify(source.name)}-{sync.__name__}")
|
||||||
try:
|
try:
|
||||||
|
|
Reference in a new issue