Skip to content

Commit

Permalink
enterprise: bump license usage task frequency (#7215)
Browse files Browse the repository at this point in the history
Signed-off-by: Jens Langhammer <jens@goauthentik.io>
  • Loading branch information
BeryJu authored Oct 18, 2023
1 parent 3514723 commit 6ba4f4d
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 3 deletions.
3 changes: 3 additions & 0 deletions authentik/enterprise/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,9 @@ def is_valid(self) -> bool:

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(),
Expand Down
2 changes: 1 addition & 1 deletion authentik/enterprise/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
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"},
}
}
3 changes: 1 addition & 2 deletions authentik/enterprise/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,4 @@
@CELERY_APP.task()
def calculate_license():
"""Calculate licensing status"""
total = LicenseKey.get_total()
total.record_usage()
LicenseKey.get_total().record_usage()

0 comments on commit 6ba4f4d

Please sign in to comment.