From 658dc63c4c427dea82e5c628c03c7c43a87c23ae Mon Sep 17 00:00:00 2001 From: Jens Langhammer Date: Tue, 19 Jul 2022 11:52:23 +0200 Subject: [PATCH] lifecycle: revert waiting for lock, launch managed reconcile on app import Signed-off-by: Jens Langhammer --- authentik/managed/apps.py | 5 +++++ lifecycle/ak | 5 ----- lifecycle/migrate.py | 11 ----------- 3 files changed, 5 insertions(+), 16 deletions(-) diff --git a/authentik/managed/apps.py b/authentik/managed/apps.py index 8bd46174a..b465ae797 100644 --- a/authentik/managed/apps.py +++ b/authentik/managed/apps.py @@ -8,3 +8,8 @@ class AuthentikManagedConfig(AppConfig): name = "authentik.managed" label = "authentik_managed" verbose_name = "authentik Managed" + + def ready(self) -> None: + from authentik.managed.tasks import managed_reconcile + + managed_reconcile.delay() diff --git a/lifecycle/ak b/lifecycle/ak index 2f1c83858..c304952ff 100755 --- a/lifecycle/ak +++ b/lifecycle/ak @@ -44,11 +44,6 @@ if [[ "$1" == "server" ]]; then /authentik-proxy elif [[ "$1" == "worker" ]]; then wait_for_db - # Check if the migration lock is set, and exit if so - # the orchestrator should restart this container, and this prevents - # errors when startup tasks are attempted to be run without - # migrations in place - python -m lifecycle.migrate check_lock echo "worker" > $MODE_FILE check_if_root "celery -A authentik.root.celery worker -Ofair --max-tasks-per-child=1 --autoscale 3,1 -E -B -s /tmp/celerybeat-schedule -Q authentik,authentik_scheduled,authentik_events" elif [[ "$1" == "bash" ]]; then diff --git a/lifecycle/migrate.py b/lifecycle/migrate.py index 1687171fd..6be15ce1e 100755 --- a/lifecycle/migrate.py +++ b/lifecycle/migrate.py @@ -1,7 +1,6 @@ #!/usr/bin/env python """System Migration handler""" import os -import sys from importlib.util import module_from_spec, spec_from_file_location from inspect import getmembers, isclass from pathlib import Path @@ -51,12 +50,6 @@ def release_lock(): curr.execute("SELECT pg_advisory_unlock(%s)", (ADV_LOCK_UID,)) -def is_locked(): - """Check if lock is currently active (used by worker to wait for migrations)""" - curr.execute("SELECT count(*) FROM pg_locks WHERE objid = %s", (ADV_LOCK_UID,)) - return curr.fetchall()[0][0] - - if __name__ == "__main__": conn = connect( dbname=CONFIG.y("postgresql.name"), @@ -66,10 +59,6 @@ if __name__ == "__main__": port=int(CONFIG.y("postgresql.port")), ) curr = conn.cursor() - if len(sys.argv) > 1: - if sys.argv[1] == "check_lock": - sys.exit(is_locked()) - try: for migration in Path(__file__).parent.absolute().glob("system_migrations/*.py"): spec = spec_from_file_location("lifecycle.system_migrations", migration)