Skip to content

Commit d56ddc3

Browse files
risssonauthentik-automation[bot]
authored andcommitted
tasks: delay startup signals (#17769)
1 parent 907ea8b commit d56ddc3

File tree

3 files changed

+10
-7
lines changed

3 files changed

+10
-7
lines changed

authentik/root/settings.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -429,6 +429,7 @@
429429
},
430430
),
431431
("dramatiq.results.middleware.Results", {"store_results": True}),
432+
("authentik.tasks.middleware.StartupSignalsMiddleware", {}),
432433
("authentik.tasks.middleware.CurrentTask", {}),
433434
("authentik.tasks.middleware.TenantMiddleware", {}),
434435
("authentik.tasks.middleware.ModelDataMiddleware", {}),

authentik/tasks/middleware.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
from authentik.events.models import Event, EventAction
2424
from authentik.lib.sentry import should_ignore_exception
2525
from authentik.lib.utils.reflection import class_to_path
26+
from authentik.root.signals import post_startup, pre_startup, startup
2627
from authentik.tasks.models import Task, TaskLog, TaskStatus, WorkerStatus
2728
from authentik.tenants.models import Tenant
2829
from authentik.tenants.utils import get_current_tenant
@@ -32,6 +33,14 @@
3233
DB_ERRORS = (OperationalError, Error)
3334

3435

36+
class StartupSignalsMiddleware(Middleware):
37+
def after_process_boot(self, broker: Broker):
38+
_startup_sender = type("WorkerStartup", (object,), {})
39+
pre_startup.send(sender=_startup_sender)
40+
startup.send(sender=_startup_sender)
41+
post_startup.send(sender=_startup_sender)
42+
43+
3544
class CurrentTask(BaseCurrentTask):
3645
@classmethod
3746
def get_task(cls) -> Task:

authentik/tasks/setup.py

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,3 @@
55
import django # noqa: E402
66

77
django.setup()
8-
9-
from authentik.root.signals import post_startup, pre_startup, startup # noqa: E402
10-
11-
_startup_sender = type("WorkerStartup", (object,), {})
12-
pre_startup.send(sender=_startup_sender)
13-
startup.send(sender=_startup_sender)
14-
post_startup.send(sender=_startup_sender)

0 commit comments

Comments
 (0)