From 2cca8cd830fd00012fe9a2d86aba656578c7f0e0 Mon Sep 17 00:00:00 2001 From: James Greenhill Date: Mon, 11 Sep 2023 19:44:32 -0700 Subject: [PATCH] add fields to the frontend for incremental scheduling --- .../src/pages/Backups/ScheduledBackups.tsx | 18 ++++++++++++++++-- housewatch/celery.py | 16 +++++++++------- 2 files changed, 25 insertions(+), 9 deletions(-) diff --git a/frontend/src/pages/Backups/ScheduledBackups.tsx b/frontend/src/pages/Backups/ScheduledBackups.tsx index 31a1099..37c26c8 100644 --- a/frontend/src/pages/Backups/ScheduledBackups.tsx +++ b/frontend/src/pages/Backups/ScheduledBackups.tsx @@ -12,6 +12,7 @@ interface ScheduleRow { last_run_time: string cluster: string schedule: string + incremental_schedule: string table: string database: string bucket: string @@ -26,6 +27,7 @@ interface Backups { type FieldType = { cluster?: string schedule?: string + incremental_schedule?: string database?: string table?: string bucket?: string @@ -130,6 +132,7 @@ export default function ScheduledBackups() { }, { title: 'Cluster', dataIndex: 'cluster' }, { title: 'Schedule', dataIndex: 'schedule' }, + { title: 'Incremental Schedule', dataIndex: 'incremental_schedule' }, { title: 'Last Run Time', dataIndex: 'last_run_time' }, { title: 'Database', dataIndex: 'database' }, { title: 'Table', dataIndex: 'table' }, @@ -207,6 +210,17 @@ export default function ScheduledBackups() { + + label="Incremental Schedule" + name="incremental_schedule" + initialValue="0 0 * * *" + rules={[ + { required: true, message: 'Please provide a cron schedule for the incremental backup' }, + ]} + > + + + label="Database" name="database" @@ -247,7 +261,7 @@ export default function ScheduledBackups() { label="AWS Access Key ID" name="aws_access_key_id" initialValue="AKIAIOSFODNN7EXAMPLE" - rules={[{ required: false, message: 'AWS Access Key ID to use for access to the S3 bucket' }]} + rules={[{ required: true, message: 'AWS Access Key ID to use for access to the S3 bucket' }]} > @@ -256,7 +270,7 @@ export default function ScheduledBackups() { label="AWS Secret Access Key" name="aws_secret_access_key" initialValue="wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY" - rules={[{ required: false, message: 'AWS Secret Access Key used to access S3 bucket' }]} + rules={[{ required: true, message: 'AWS Secret Access Key used to access S3 bucket' }]} > diff --git a/housewatch/celery.py b/housewatch/celery.py index d5be634..2bbe4ad 100644 --- a/housewatch/celery.py +++ b/housewatch/celery.py @@ -53,19 +53,21 @@ def schedule_backups(): if nr.tzinfo is None: nr = timezone.make_aware(nr) - lirt = backup.last_incremental_run_time - if lirt is None: - lirt = backup.created_at - nir = croniter(backup.incremental_schedule, lirt).get_next(datetime) - if nir.tzinfo is None: - nir = timezone.make_aware(nir) + nir = None + if backup.incremental_schedule is not None: + lirt = backup.last_incremental_run_time + if lirt is None: + lirt = backup.created_at + nir = croniter(backup.incremental_schedule, lirt).get_next(datetime) + if nir.tzinfo is None: + nir = timezone.make_aware(nir) logger.info("Checking backup", backup_id=backup.id, next_run=nr, next_incremental_run=nir, now=now) if nr < now: run_backup.delay(backup.id) backup.last_run_time = now backup.save() - if nir < now: + elif backup.incremental_schedule is not None and nir < now: run_backup.delay(backup.id, incremental=True) backup.last_incremental_run_time = now backup.save()