@ -31,9 +31,11 @@ class AuthentikEnterpriseConfig(EnterpriseConfig):
|
|||||||
|
|
||||||
@property
|
@property
|
||||||
def tenant_schedule_specs(self) -> list[ScheduleSpec]:
|
def tenant_schedule_specs(self) -> list[ScheduleSpec]:
|
||||||
|
from authentik.enterprise.tasks import enterprise_update_usage
|
||||||
|
|
||||||
return [
|
return [
|
||||||
ScheduleSpec(
|
ScheduleSpec(
|
||||||
actor_name="authentik.enterprise.tasks.enterprise_update_usage",
|
actor_name=enterprise_update_usage.actor_name,
|
||||||
crontab=f"{fqdn_rand('enterprise_update_usage')} */2 * * *",
|
crontab=f"{fqdn_rand('enterprise_update_usage')} */2 * * *",
|
||||||
),
|
),
|
||||||
]
|
]
|
||||||
|
|||||||
@ -10,6 +10,7 @@ from django.utils.timezone import get_current_timezone
|
|||||||
from authentik.enterprise.license import CACHE_KEY_ENTERPRISE_LICENSE
|
from authentik.enterprise.license import CACHE_KEY_ENTERPRISE_LICENSE
|
||||||
from authentik.enterprise.models import License
|
from authentik.enterprise.models import License
|
||||||
from authentik.enterprise.tasks import enterprise_update_usage
|
from authentik.enterprise.tasks import enterprise_update_usage
|
||||||
|
from authentik.tasks.schedules.models import Schedule
|
||||||
|
|
||||||
|
|
||||||
@receiver(pre_save, sender=License)
|
@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, **_):
|
def post_save_license(sender: type[License], instance: License, **_):
|
||||||
"""Trigger license usage calculation when license is saved"""
|
"""Trigger license usage calculation when license is saved"""
|
||||||
cache.delete(CACHE_KEY_ENTERPRISE_LICENSE)
|
cache.delete(CACHE_KEY_ENTERPRISE_LICENSE)
|
||||||
enterprise_update_usage.send()
|
Schedule.dispatch_by_actor(enterprise_update_usage)
|
||||||
|
|
||||||
|
|
||||||
@receiver(post_delete, sender=License)
|
@receiver(post_delete, sender=License)
|
||||||
|
|||||||
@ -59,6 +59,14 @@ class Schedule(SerializerModel):
|
|||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.uid
|
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
|
@property
|
||||||
def serializer(self):
|
def serializer(self):
|
||||||
from authentik.tasks.schedules.api import ScheduleSerializer
|
from authentik.tasks.schedules.api import ScheduleSerializer
|
||||||
|
|||||||
Reference in New Issue
Block a user