*: don't dispatch tasks on startup of server (#3033)

Signed-off-by: Jens Langhammer <jens.langhammer@beryju.org>
This commit is contained in:
Jens L 2022-06-03 18:29:24 +02:00 committed by GitHub
parent 7ee655a318
commit 0c591a50e3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 44 additions and 23 deletions

View File

@ -12,7 +12,4 @@ class AuthentikAdminConfig(AppConfig):
verbose_name = "authentik Admin" verbose_name = "authentik Admin"
def ready(self): def ready(self):
from authentik.admin.tasks import clear_update_notifications
clear_update_notifications.delay()
import_module("authentik.admin.signals") import_module("authentik.admin.signals")

View File

@ -8,9 +8,3 @@ class AuthentikManagedConfig(AppConfig):
name = "authentik.managed" name = "authentik.managed"
label = "authentik_managed" label = "authentik_managed"
verbose_name = "authentik Managed" verbose_name = "authentik Managed"
def ready(self) -> None:
from authentik.managed.tasks import managed_reconcile
# pyright: reportGeneralTypeIssues=false
managed_reconcile.delay() # pylint: disable=no-value-for-parameter

View File

@ -2,7 +2,6 @@
from importlib import import_module from importlib import import_module
from django.apps import AppConfig from django.apps import AppConfig
from django.db import ProgrammingError
from structlog.stdlib import get_logger from structlog.stdlib import get_logger
LOGGER = get_logger() LOGGER = get_logger()
@ -18,10 +17,3 @@ class AuthentikOutpostConfig(AppConfig):
def ready(self): def ready(self):
import_module("authentik.outposts.signals") import_module("authentik.outposts.signals")
import_module("authentik.outposts.managed") import_module("authentik.outposts.managed")
try:
from authentik.outposts.tasks import outpost_controller_all, outpost_local_connection
outpost_local_connection.delay()
outpost_controller_all.delay()
except ProgrammingError:
pass

View File

@ -12,8 +12,4 @@ class AuthentikProviderProxyConfig(AppConfig):
verbose_name = "authentik Providers.Proxy" verbose_name = "authentik Providers.Proxy"
def ready(self) -> None: def ready(self) -> None:
from authentik.providers.proxy.tasks import proxy_set_defaults
import_module("authentik.providers.proxy.managed") import_module("authentik.providers.proxy.managed")
proxy_set_defaults.delay()

View File

@ -10,8 +10,10 @@ from celery.signals import (
task_internal_error, task_internal_error,
task_postrun, task_postrun,
task_prerun, task_prerun,
worker_ready,
) )
from django.conf import settings from django.conf import settings
from django.db import ProgrammingError
from structlog.stdlib import get_logger from structlog.stdlib import get_logger
from authentik.core.middleware import LOCAL from authentik.core.middleware import LOCAL
@ -74,6 +76,29 @@ def task_error_hook(task_id, exception: Exception, traceback, *args, **kwargs):
Event.new(EventAction.SYSTEM_EXCEPTION, message=exception_to_string(exception)).save() Event.new(EventAction.SYSTEM_EXCEPTION, message=exception_to_string(exception)).save()
@worker_ready.connect
def worker_ready_hook(*args, **kwargs):
"""Run certain tasks on worker start"""
from authentik.admin.tasks import clear_update_notifications
from authentik.managed.tasks import managed_reconcile
from authentik.outposts.tasks import outpost_controller_all, outpost_local_connection
from authentik.providers.proxy.tasks import proxy_set_defaults
tasks = [
clear_update_notifications,
outpost_local_connection,
outpost_controller_all,
proxy_set_defaults,
managed_reconcile,
]
LOGGER.info("Dispatching startup tasks...")
for task in tasks:
try:
task.delay()
except ProgrammingError as exc:
LOGGER.warning("Startup task failed", task=task, exc=exc)
# Using a string here means the worker doesn't have to serialize # Using a string here means the worker doesn't have to serialize
# the configuration object to child processes. # the configuration object to child processes.
# - namespace='CELERY' means all celery-related configuration keys # - namespace='CELERY' means all celery-related configuration keys

View File

@ -34,6 +34,5 @@ class AuthentikSourceOAuthConfig(AppConfig):
for source_type in AUTHENTIK_SOURCES_OAUTH_TYPES: for source_type in AUTHENTIK_SOURCES_OAUTH_TYPES:
try: try:
import_module(source_type) import_module(source_type)
LOGGER.debug("Loaded OAuth Source Type", type=source_type)
except ImportError as exc: except ImportError as exc:
LOGGER.debug(str(exc)) LOGGER.warning("Failed to load OAuth Source", exc=exc)

View File

@ -27,6 +27,24 @@ slug: "2022.6"
## Minor changes/fixes ## Minor changes/fixes
- api: migrate to openapi generator v6 (#2968)
- api: update API browser to match admin UI and auto-switch theme
- core: improve loading speed of flow background
- ensure all viewsets have filter and search and add tests (#2946)
- flows: fix re-imports of entries with identical PK re-creating objects
- lifecycle: cleanup prometheus metrics, remove PII (#2972)
- policies: fix incorrect bound_to count
- providers/oauth2: add configuration error event when wrong redirect uri is used in token request
- providers/oauth2: handle attribute errors when validation JWK contains private key
- providers/oauth2: only set expiry on user when it was freshly created
- providers/oauth2: regex-escape URLs when set to blank
- root: Add docker-compose postgresql and redis healthchecks (#2958)
- root: disable session_save_every_request as it causes race conditions
- web/elements: fix top-right dialog close button not resetting form
- web/elements: fix used_by refreshing for all elements when using DeleteBulkForm
- web/user: fix static prompt fields being rendered with label
- web/user: improve ux for restarting user settings flow
## Upgrading ## Upgrading
This release does not introduce any new requirements. This release does not introduce any new requirements.