Signed-off-by: Marc 'risson' Schmitt <marc.schmitt@risson.space>
This commit is contained in:
Marc 'risson' Schmitt
2025-06-11 17:45:05 +02:00
parent 5e2af4a740
commit f2926fa1eb
12 changed files with 22 additions and 55 deletions

View File

@ -1,5 +1,4 @@
import dramatiq
from django.conf import settings
from dramatiq.broker import Broker, get_broker
from dramatiq.encoder import PickleEncoder
from dramatiq.middleware import (

View File

@ -1,4 +1,3 @@
from django.apps import apps
from authentik.blueprints.apps import ManagedAppConfig
from authentik.lib.utils.reflection import get_apps
@ -15,21 +14,12 @@ class AuthentikTasksSchedulesConfig(ManagedAppConfig):
def tenant_schedule_specs(self) -> list[ScheduleSpec]:
from authentik.tasks.schedules.models import ScheduledModel
def is_scheduled_model(klass) -> bool:
if ScheduledModel in klass.__bases__:
return True
return any(is_scheduled_model(klass) for klass in klass.__bases__)
schedules = []
for Model in apps.get_models():
if not is_scheduled_model(Model):
continue
for Model in ScheduledModel.models():
for obj in Model.objects.all():
for spec in obj.schedule_specs:
spec.rel_obj = obj
schedules.append(spec)
return schedules
def _reconcile_schedules(self, specs: list[ScheduleSpec]):

View File

@ -3,6 +3,7 @@ from uuid import uuid4
import pgtrigger
from cron_converter import Cron
from django.apps import apps
from django.contrib.contenttypes.fields import GenericForeignKey, GenericRelation
from django.contrib.contenttypes.models import ContentType
from django.core.exceptions import ValidationError
@ -109,6 +110,15 @@ class ScheduledModel(models.Model):
class Meta:
abstract = True
@classmethod
def models(cls) -> list[models.Model]:
def is_scheduled_model(klass) -> bool:
if ScheduledModel in klass.__bases__:
return True
return any(is_scheduled_model(klass) for klass in klass.__bases__)
return [model for model in apps.get_models() if is_scheduled_model(model)]
@property
def schedule_specs(self) -> list[ScheduleSpec]:
raise NotImplementedError