Skip to content

Commit

Permalink
add fields to the frontend for incremental scheduling
Browse files Browse the repository at this point in the history
  • Loading branch information
fuziontech committed Sep 12, 2023
1 parent f81c385 commit 2cca8cd
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 9 deletions.
18 changes: 16 additions & 2 deletions frontend/src/pages/Backups/ScheduledBackups.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ interface ScheduleRow {
last_run_time: string
cluster: string
schedule: string
incremental_schedule: string
table: string
database: string
bucket: string
Expand All @@ -26,6 +27,7 @@ interface Backups {
type FieldType = {
cluster?: string
schedule?: string
incremental_schedule?: string
database?: string
table?: string
bucket?: string
Expand Down Expand Up @@ -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' },
Expand Down Expand Up @@ -207,6 +210,17 @@ export default function ScheduledBackups() {
<Input />
</Form.Item>

<Form.Item<FieldType>
label="Incremental Schedule"
name="incremental_schedule"
initialValue="0 0 * * *"
rules={[
{ required: true, message: 'Please provide a cron schedule for the incremental backup' },
]}
>
<Input />
</Form.Item>

<Form.Item<FieldType>
label="Database"
name="database"
Expand Down Expand Up @@ -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' }]}
>
<Input />
</Form.Item>
Expand All @@ -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' }]}
>
<Input />
</Form.Item>
Expand Down
16 changes: 9 additions & 7 deletions housewatch/celery.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit 2cca8cd

Please sign in to comment.