Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions src/aap_eda/core/enums.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,3 +231,15 @@ class AnalyticsCredentialType(DjangoStrEnum):
AnalyticsCredentialType.BASIC,
AnalyticsCredentialType.OAUTH,
]


class ManagementJobType(DjangoStrEnum):
CLEANUP_AUDIT_LOGS = "cleanup_audit_logs"
CLEANUP_STALE_ACTIVATIONS = "cleanup_stale_activations"


class ExecutionStatus(DjangoStrEnum):
PENDING = "pending"
RUNNING = "running"
COMPLETED = "completed"
FAILED = "failed"
150 changes: 150 additions & 0 deletions src/aap_eda/core/migrations/0071_management_jobs.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
# Generated by Django 5.2.13 on 2026-04-21 18:49

import django.db.models.deletion
from django.db import migrations, models

import aap_eda.core.enums


class Migration(migrations.Migration):
dependencies = [
("core", "0070_activation_enable_persistence_and_more"),
]

operations = [
migrations.CreateModel(
name="ManagementJob",
fields=[
(
"id",
models.BigAutoField(
auto_created=True,
primary_key=True,
serialize=False,
verbose_name="ID",
),
),
("name", models.TextField(unique=True)),
("description", models.TextField(blank=True, default="")),
(
"job_type",
models.TextField(
choices=[
("cleanup_audit_logs", "cleanup_audit_logs"),
(
"cleanup_stale_activations",
"cleanup_stale_activations",
),
],
default=aap_eda.core.enums.ManagementJobType[
"CLEANUP_AUDIT_LOGS"
],
),
),
("is_enabled", models.BooleanField(default=True)),
("parameters", models.JSONField(blank=True, default=dict)),
("created_at", models.DateTimeField(auto_now_add=True)),
("modified_at", models.DateTimeField(auto_now=True)),
(
"organization",
models.ForeignKey(
on_delete=django.db.models.deletion.CASCADE,
to="core.organization",
),
),
],
options={
"db_table": "core_management_job",
"ordering": ("-created_at",),
},
),
migrations.CreateModel(
name="ManagementJobExecution",
fields=[
(
"id",
models.BigAutoField(
auto_created=True,
primary_key=True,
serialize=False,
verbose_name="ID",
),
),
(
"status",
models.TextField(
choices=[
("pending", "pending"),
("running", "running"),
("completed", "completed"),
("failed", "failed"),
],
default=aap_eda.core.enums.ExecutionStatus["PENDING"],
),
),
("started_at", models.DateTimeField(blank=True, null=True)),
("finished_at", models.DateTimeField(blank=True, null=True)),
("output", models.TextField(blank=True, default="")),
("errors", models.TextField(blank=True, default="")),
("created_at", models.DateTimeField(auto_now_add=True)),
(
"management_job",
models.ForeignKey(
on_delete=django.db.models.deletion.CASCADE,
related_name="executions",
to="core.managementjob",
),
),
(
"organization",
models.ForeignKey(
on_delete=django.db.models.deletion.CASCADE,
to="core.organization",
),
),
],
options={
"db_table": "core_management_job_execution",
"ordering": ("-started_at",),
},
),
migrations.CreateModel(
name="ManagementJobSchedule",
fields=[
(
"id",
models.BigAutoField(
auto_created=True,
primary_key=True,
serialize=False,
verbose_name="ID",
),
),
("schedule", models.TextField(help_text="Cron expression")),
("next_run_at", models.DateTimeField(blank=True, null=True)),
("last_run_at", models.DateTimeField(blank=True, null=True)),
("is_enabled", models.BooleanField(default=True)),
("created_at", models.DateTimeField(auto_now_add=True)),
("modified_at", models.DateTimeField(auto_now=True)),
(
"management_job",
models.ForeignKey(
on_delete=django.db.models.deletion.CASCADE,
related_name="schedules",
to="core.managementjob",
),
),
(
"organization",
models.ForeignKey(
on_delete=django.db.models.deletion.CASCADE,
to="core.organization",
),
),
],
options={
"db_table": "core_management_job_schedule",
"ordering": ("-next_run_at",),
},
),
]
9 changes: 9 additions & 0 deletions src/aap_eda/core/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@
JobInstanceEvent,
JobInstanceHost,
)
from .management_job import (
ManagementJob,
ManagementJobExecution,
ManagementJobSchedule,
)
from .organization import Organization
from .project import Project
from .queue import ActivationRequestQueue
Expand Down Expand Up @@ -65,6 +70,9 @@
"Organization",
"Team",
"EventStream",
"ManagementJob",
"ManagementJobExecution",
"ManagementJobSchedule",
"Setting",
]

Expand All @@ -73,6 +81,7 @@
EdaCredential,
CredentialInputSource,
DecisionEnvironment,
ManagementJob,
Project,
Organization,
Team,
Expand Down
80 changes: 80 additions & 0 deletions src/aap_eda/core/models/management_job.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
# Copyright 2026 Red Hat, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from django.db import models

from aap_eda.core.enums import ExecutionStatus, ManagementJobType

from .base import BaseOrgModel, UniqueNamedModel

__all__ = (
"ManagementJob",
"ManagementJobSchedule",
"ManagementJobExecution",
)


class ManagementJob(BaseOrgModel, UniqueNamedModel):
class Meta:
db_table = "core_management_job"
ordering = ("-created_at",)

description = models.TextField(default="", blank=True)
job_type = models.TextField(
choices=ManagementJobType.choices(),
default=ManagementJobType.CLEANUP_AUDIT_LOGS,
)
is_enabled = models.BooleanField(default=True)
parameters = models.JSONField(default=dict, blank=True)
created_at = models.DateTimeField(auto_now_add=True, null=False)
modified_at = models.DateTimeField(auto_now=True, null=False)


class ManagementJobSchedule(BaseOrgModel):
class Meta:
db_table = "core_management_job_schedule"
ordering = ("-next_run_at",)

management_job = models.ForeignKey(
ManagementJob,
on_delete=models.CASCADE,
related_name="schedules",
)
schedule = models.TextField(help_text="Cron expression")
next_run_at = models.DateTimeField(null=True, blank=True)
last_run_at = models.DateTimeField(null=True, blank=True)
is_enabled = models.BooleanField(default=True)
created_at = models.DateTimeField(auto_now_add=True, null=False)
modified_at = models.DateTimeField(auto_now=True, null=False)


class ManagementJobExecution(BaseOrgModel):
class Meta:
db_table = "core_management_job_execution"
ordering = ("-started_at",)

management_job = models.ForeignKey(
ManagementJob,
on_delete=models.CASCADE,
related_name="executions",
)
status = models.TextField(
choices=ExecutionStatus.choices(),
default=ExecutionStatus.PENDING,
)
started_at = models.DateTimeField(null=True, blank=True)
finished_at = models.DateTimeField(null=True, blank=True)
output = models.TextField(default="", blank=True)
errors = models.TextField(default="", blank=True)
created_at = models.DateTimeField(auto_now_add=True, null=False)
Loading
Loading