Add action ID option to schedules

This commit is contained in:
amcmanu3 2024-05-25 13:51:40 -04:00
parent c2dd307369
commit f8626633cf
4 changed files with 64 additions and 1 deletions

View File

@ -123,6 +123,7 @@ class ManagementController:
cron_string="* * * * *",
parent=None,
delay=0,
action_id=None,
):
return HelpersManagement.create_scheduled_task(
server_id,
@ -137,6 +138,7 @@ class ManagementController:
cron_string,
parent,
delay,
action_id,
)
@staticmethod

View File

@ -89,6 +89,7 @@ class Schedules(BaseModel):
interval_type = CharField()
start_time = CharField(null=True)
command = CharField(null=True)
action_id = CharField(null=True)
name = CharField()
one_time = BooleanField(default=False)
cron_string = CharField(default="")
@ -114,6 +115,7 @@ class Backups(BaseModel):
shutdown = BooleanField(default=False)
before = CharField(default="")
after = CharField(default="")
enabled = BooleanField(default=True)
class Meta:
table_name = "backups"
@ -268,6 +270,7 @@ class HelpersManagement:
cron_string="* * * * *",
parent=None,
delay=0,
action_id=None,
):
sch_id = Schedules.insert(
{
@ -278,6 +281,7 @@ class HelpersManagement:
Schedules.interval_type: interval_type,
Schedules.start_time: start_time,
Schedules.command: command,
Schedules.action_id: action_id,
Schedules.name: name,
Schedules.one_time: one_time,
Schedules.cron_string: cron_string,

View File

@ -337,6 +337,7 @@ class TasksManager:
job_data["cron_string"],
job_data["parent"],
job_data["delay"],
job_data.get("action_id", None),
)
# Checks to make sure some doofus didn't actually make the newly

View File

@ -5,7 +5,7 @@ import logging
from app.classes.shared.console import Console
from app.classes.shared.migration import Migrator, MigrateHistory
from app.classes.models.management import Backups
from app.classes.models.management import Backups, Schedules
logger = logging.getLogger(__name__)
@ -19,6 +19,10 @@ def migrate(migrator: Migrator, database, **kwargs):
migrator.add_columns("backups", backup_id=peewee.UUIDField(default=uuid.uuid4))
migrator.add_columns("backups", backup_name=peewee.CharField(default="Default"))
migrator.add_columns("backups", backup_location=peewee.CharField(default=""))
migrator.add_columns("backups", enabled=peewee.BooleanField(default=True))
migrator.add_columns(
"schedules", action_id=peewee.CharField(null=True, default=None)
)
class Servers(peewee.Model):
server_id = peewee.CharField(primary_key=True, default=str(uuid.uuid4()))
@ -58,12 +62,34 @@ def migrate(migrator: Migrator, database, **kwargs):
shutdown = peewee.BooleanField(default=False)
before = peewee.CharField(default="")
after = peewee.CharField(default="")
enabled = peewee.BooleanField(default=True)
class Meta:
table_name = "new_backups"
database = db
class NewSchedules(peewee.Model):
schedule_id = peewee.IntegerField(unique=True, primary_key=True)
server_id = peewee.ForeignKeyField(Servers, backref="schedule_server")
enabled = peewee.BooleanField()
action = peewee.CharField()
interval = peewee.IntegerField()
interval_type = peewee.CharField()
start_time = peewee.CharField(null=True)
command = peewee.CharField(null=True)
action_id = peewee.CharField(null=True)
name = peewee.CharField()
one_time = peewee.BooleanField(default=False)
cron_string = peewee.CharField(default="")
parent = peewee.IntegerField(null=True)
delay = peewee.IntegerField(default=0)
next_run = peewee.CharField(default="")
class Meta:
table_name = "new_schedules"
migrator.create_table(NewBackups)
migrator.create_table(NewSchedules)
migrator.run()
@ -83,6 +109,7 @@ def migrate(migrator: Migrator, database, **kwargs):
shutdown=backup.shutdown,
before=backup.before,
after=backup.after,
enabled=True,
)
# Drop the existing backups table
@ -92,6 +119,35 @@ def migrate(migrator: Migrator, database, **kwargs):
migrator.rename_table("new_backups", "backups")
migrator.drop_columns("servers", ["backup_path"])
for schedule in Schedules.select():
action_id = None
if schedule.command == "backup_server":
backup = NewBackups.get(NewBackups.server_id == schedule.server_id)
action_id = backup.backup_id
NewSchedules.create(
schedule_id=schedule.schedule_id,
server_id=schedule.server_id,
enabled=schedule.enabled,
action=schedule.action,
interval=schedule.interval,
interval_type=schedule.interval_type,
start_time=schedule.start_time,
command=schedule.command,
action_id=action_id,
name=schedule.name,
one_time=schedule.one_time,
cron_string=schedule.cron_string,
parent=schedule.parent,
delay=schedule.delay,
next_run=schedule.next_run,
)
# Drop the existing backups table
migrator.drop_table("schedules")
# Rename the new table to backups
migrator.rename_table("new_schedules", "schedules")
def rollback(migrator: Migrator, database, **kwargs):
"""