diff --git a/authentik/enterprise/models.py b/authentik/enterprise/models.py index aca8f0b02..5def8ad37 100644 --- a/authentik/enterprise/models.py +++ b/authentik/enterprise/models.py @@ -136,6 +136,9 @@ class LicenseKey: def record_usage(self): """Capture the current validity status and metrics and save them""" + threshold = now() - timedelta(hours=8) + if LicenseUsage.objects.filter(record_date__gte=threshold).exists(): + return LicenseUsage.objects.create( user_count=self.get_default_user_count(), external_user_count=self.get_external_user_count(), diff --git a/authentik/enterprise/settings.py b/authentik/enterprise/settings.py index af1da7294..87aaea71b 100644 --- a/authentik/enterprise/settings.py +++ b/authentik/enterprise/settings.py @@ -6,7 +6,7 @@ from authentik.lib.utils.time import fqdn_rand CELERY_BEAT_SCHEDULE = { "enterprise_calculate_license": { "task": "authentik.enterprise.tasks.calculate_license", - "schedule": crontab(minute=fqdn_rand("calculate_license"), hour="*/8"), + "schedule": crontab(minute=fqdn_rand("calculate_license"), hour="*/2"), "options": {"queue": "authentik_scheduled"}, } } diff --git a/authentik/enterprise/tasks.py b/authentik/enterprise/tasks.py index 2931a726b..2063cf07a 100644 --- a/authentik/enterprise/tasks.py +++ b/authentik/enterprise/tasks.py @@ -6,5 +6,4 @@ from authentik.root.celery import CELERY_APP @CELERY_APP.task() def calculate_license(): """Calculate licensing status""" - total = LicenseKey.get_total() - total.record_usage() + LicenseKey.get_total().record_usage()