diff --git a/authentik/enterprise/apps.py b/authentik/enterprise/apps.py index 4bbc710042..d1d9963670 100644 --- a/authentik/enterprise/apps.py +++ b/authentik/enterprise/apps.py @@ -31,9 +31,11 @@ class AuthentikEnterpriseConfig(EnterpriseConfig): @property def tenant_schedule_specs(self) -> list[ScheduleSpec]: + from authentik.enterprise.tasks import enterprise_update_usage + return [ ScheduleSpec( - actor_name="authentik.enterprise.tasks.enterprise_update_usage", + actor_name=enterprise_update_usage.actor_name, crontab=f"{fqdn_rand('enterprise_update_usage')} */2 * * *", ), ] diff --git a/authentik/enterprise/signals.py b/authentik/enterprise/signals.py index d4048c43bd..78eedf0b08 100644 --- a/authentik/enterprise/signals.py +++ b/authentik/enterprise/signals.py @@ -10,6 +10,7 @@ from django.utils.timezone import get_current_timezone from authentik.enterprise.license import CACHE_KEY_ENTERPRISE_LICENSE from authentik.enterprise.models import License from authentik.enterprise.tasks import enterprise_update_usage +from authentik.tasks.schedules.models import Schedule @receiver(pre_save, sender=License) @@ -26,7 +27,7 @@ def pre_save_license(sender: type[License], instance: License, **_): def post_save_license(sender: type[License], instance: License, **_): """Trigger license usage calculation when license is saved""" cache.delete(CACHE_KEY_ENTERPRISE_LICENSE) - enterprise_update_usage.send() + Schedule.dispatch_by_actor(enterprise_update_usage) @receiver(post_delete, sender=License) diff --git a/authentik/tasks/schedules/models.py b/authentik/tasks/schedules/models.py index 9a387a762c..a681d51e64 100644 --- a/authentik/tasks/schedules/models.py +++ b/authentik/tasks/schedules/models.py @@ -59,6 +59,14 @@ class Schedule(SerializerModel): def __str__(self): return self.uid + @classmethod + def dispatch_by_actor(cls, actor: Actor): + """Dispatch a schedule by looking up its actor. + Only available for schedules without custom arguments.""" + schedule = cls.objects.filter(actor_name=actor.actor_name, paused=False).first() + if schedule: + schedule.send() + @property def serializer(self): from authentik.tasks.schedules.api import ScheduleSerializer