outposts: optimise signals to not always trigger
This commit is contained in:
parent
f3ccb5341d
commit
60f52f102a
|
@ -4,11 +4,19 @@ from django.db.models.signals import post_save, pre_delete
|
||||||
from django.dispatch import receiver
|
from django.dispatch import receiver
|
||||||
from structlog.stdlib import get_logger
|
from structlog.stdlib import get_logger
|
||||||
|
|
||||||
|
from authentik.core.models import Provider
|
||||||
|
from authentik.crypto.models import CertificateKeyPair
|
||||||
from authentik.lib.utils.reflection import class_to_path
|
from authentik.lib.utils.reflection import class_to_path
|
||||||
from authentik.outposts.models import Outpost
|
from authentik.outposts.models import Outpost, OutpostServiceConnection
|
||||||
from authentik.outposts.tasks import outpost_post_save, outpost_pre_delete
|
from authentik.outposts.tasks import outpost_post_save, outpost_pre_delete
|
||||||
|
|
||||||
LOGGER = get_logger()
|
LOGGER = get_logger()
|
||||||
|
UPDATE_TRIGGERING_MODELS = (
|
||||||
|
Outpost,
|
||||||
|
OutpostServiceConnection,
|
||||||
|
Provider,
|
||||||
|
CertificateKeyPair,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
@receiver(post_save)
|
@receiver(post_save)
|
||||||
|
@ -22,6 +30,8 @@ def post_save_update(sender, instance: Model, **_):
|
||||||
return
|
return
|
||||||
if instance.__module__ == "__fake__":
|
if instance.__module__ == "__fake__":
|
||||||
return
|
return
|
||||||
|
if sender not in UPDATE_TRIGGERING_MODELS:
|
||||||
|
return
|
||||||
outpost_post_save.delay(class_to_path(instance.__class__), instance.pk)
|
outpost_post_save.delay(class_to_path(instance.__class__), instance.pk)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -124,14 +124,12 @@ def outpost_post_save(model_class: str, model_pk: Any):
|
||||||
_ = instance.token
|
_ = instance.token
|
||||||
LOGGER.debug("Trigger reconcile for outpost")
|
LOGGER.debug("Trigger reconcile for outpost")
|
||||||
outpost_controller.delay(instance.pk)
|
outpost_controller.delay(instance.pk)
|
||||||
return
|
|
||||||
|
|
||||||
if isinstance(instance, (OutpostModel, Outpost)):
|
if isinstance(instance, (OutpostModel, Outpost)):
|
||||||
LOGGER.debug(
|
LOGGER.debug(
|
||||||
"triggering outpost update from outpostmodel/outpost", instance=instance
|
"triggering outpost update from outpostmodel/outpost", instance=instance
|
||||||
)
|
)
|
||||||
outpost_send_update(instance)
|
outpost_send_update(instance)
|
||||||
return
|
|
||||||
|
|
||||||
if isinstance(instance, OutpostServiceConnection):
|
if isinstance(instance, OutpostServiceConnection):
|
||||||
LOGGER.debug("triggering ServiceConnection state update", instance=instance)
|
LOGGER.debug("triggering ServiceConnection state update", instance=instance)
|
||||||
|
|
Reference in New Issue