lifecycle: revert waiting for lock, launch managed reconcile on app import

Signed-off-by: Jens Langhammer <jens.langhammer@beryju.org>
This commit is contained in:
Jens Langhammer 2022-07-19 11:52:23 +02:00
parent 4edec5f666
commit 658dc63c4c
3 changed files with 5 additions and 16 deletions

View File

@ -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()

View File

@ -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

View File

@ -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)