diff --git a/authentik/admin/tasks.py b/authentik/admin/tasks.py index 3602a24e4..2c7e91810 100644 --- a/authentik/admin/tasks.py +++ b/authentik/admin/tasks.py @@ -54,7 +54,7 @@ def clear_update_notifications(): @CELERY_APP.task(bind=True, base=MonitoredTask) -@prefill_task() +@prefill_task def update_latest_version(self: MonitoredTask): """Update latest version info""" if CONFIG.y_bool("disable_update_check"): diff --git a/authentik/core/tasks.py b/authentik/core/tasks.py index df45b4d4b..3e18c50b4 100644 --- a/authentik/core/tasks.py +++ b/authentik/core/tasks.py @@ -29,7 +29,7 @@ LOGGER = get_logger() @CELERY_APP.task(bind=True, base=MonitoredTask) -@prefill_task() +@prefill_task def clean_expired_models(self: MonitoredTask): """Remove expired objects""" messages = [] @@ -69,7 +69,7 @@ def should_backup() -> bool: @CELERY_APP.task(bind=True, base=MonitoredTask) -@prefill_task() +@prefill_task def backup_database(self: MonitoredTask): # pragma: no cover """Database backup""" self.result_timeout_hours = 25 diff --git a/authentik/events/monitored_tasks.py b/authentik/events/monitored_tasks.py index 707aa0d3c..9c71ca6f5 100644 --- a/authentik/events/monitored_tasks.py +++ b/authentik/events/monitored_tasks.py @@ -112,13 +112,13 @@ class TaskInfo: cache.set(key, self, timeout=timeout_hours * 60 * 60) -def prefill_task(): +def prefill_task(func): """Ensure a task's details are always in cache, so it can always be triggered via API""" - def inner_wrap(func): + def wrapper(*args, **kwargs): status = TaskInfo.by_name(func.__name__) if status: - return func + return func(*args, **kwargs) TaskInfo( task_name=func.__name__, task_description=func.__doc__, @@ -131,9 +131,9 @@ def prefill_task(): finish_time=datetime.now(), ).save(86400) LOGGER.debug("prefilled task", task_name=func.__name__) - return func + return func(*args, **kwargs) - return inner_wrap + return wrapper class MonitoredTask(Task): diff --git a/authentik/managed/tasks.py b/authentik/managed/tasks.py index 5d2ebd996..2cc9b21d2 100644 --- a/authentik/managed/tasks.py +++ b/authentik/managed/tasks.py @@ -12,7 +12,7 @@ from authentik.managed.manager import ObjectManager @CELERY_APP.task(bind=True, base=MonitoredTask) -@prefill_task() +@prefill_task def managed_reconcile(self: MonitoredTask): """Run ObjectManager to ensure objects are up-to-date""" try: diff --git a/authentik/outposts/tasks.py b/authentik/outposts/tasks.py index 63d7f4370..737b1ef15 100644 --- a/authentik/outposts/tasks.py +++ b/authentik/outposts/tasks.py @@ -76,7 +76,7 @@ def outpost_service_connection_state(connection_pk: Any): @CELERY_APP.task(bind=True, base=MonitoredTask) -@prefill_task() +@prefill_task def outpost_service_connection_monitor(self: MonitoredTask): """Regularly check the state of Outpost Service Connections""" connections = OutpostServiceConnection.objects.all() @@ -126,7 +126,7 @@ def outpost_controller( @CELERY_APP.task(bind=True, base=MonitoredTask) -@prefill_task() +@prefill_task def outpost_token_ensurer(self: MonitoredTask): """Periodically ensure that all Outposts have valid Service Accounts and Tokens""" diff --git a/authentik/policies/reputation/tasks.py b/authentik/policies/reputation/tasks.py index eb6dcd6e3..3126dfca8 100644 --- a/authentik/policies/reputation/tasks.py +++ b/authentik/policies/reputation/tasks.py @@ -16,7 +16,7 @@ LOGGER = get_logger() @CELERY_APP.task(bind=True, base=MonitoredTask) -@prefill_task() +@prefill_task def save_ip_reputation(self: MonitoredTask): """Save currently cached reputation to database""" objects_to_update = [] @@ -30,7 +30,7 @@ def save_ip_reputation(self: MonitoredTask): @CELERY_APP.task(bind=True, base=MonitoredTask) -@prefill_task() +@prefill_task def save_user_reputation(self: MonitoredTask): """Save currently cached reputation to database""" objects_to_update = [] diff --git a/authentik/sources/saml/tasks.py b/authentik/sources/saml/tasks.py index 5c495956f..cb72d55d0 100644 --- a/authentik/sources/saml/tasks.py +++ b/authentik/sources/saml/tasks.py @@ -17,7 +17,7 @@ LOGGER = get_logger() @CELERY_APP.task(bind=True, base=MonitoredTask) -@prefill_task() +@prefill_task def clean_temporary_users(self: MonitoredTask): """Remove temporary users created by SAML Sources""" _now = now()