refactor(backups): only async snapshot trimming
continuous-integration/drone/push Build is failing Details

pull/73/head
Houkime 2023-11-17 15:39:21 +00:00
parent 5ac93c30ae
commit f1a452009a
4 changed files with 13 additions and 11 deletions

View File

@ -425,7 +425,10 @@ class Backups:
yearly=Backups._standardize_quotas(quotas.yearly), # type: ignore
)
)
# do not prune all autosnaps right away, this will be done by an async task
@staticmethod
def prune_all_autosnaps() -> None:
for service in get_all_services():
Backups._prune_auto_snaps(service)

View File

@ -43,16 +43,13 @@ def start_backup(
@huey.task()
def set_autobackup_quotas(quotas: AutobackupQuotas, job: Job) -> bool:
job = Jobs.add(
name="trimming autobackup snapshots",
type_id="backups.autobackup_trimming",
description="Pruning the excessive snapshots after the new autobackup quotas are set",
status=JobStatus.RUNNING,
)
def prune_autobackup_snapshots(quotas: AutobackupQuotas, job: Job) -> bool:
"""
Remove all autobackup snapshots that do not fit into quotas set
"""
Jobs.update(job, JobStatus.RUNNING)
try:
Backups.set_autobackup_quotas(quotas)
Backups.prune_all_autosnaps()
except Exception as e:
Jobs.update(job, JobStatus.ERROR, error=type(e).__name__ + ":" + str(e))
return False

View File

@ -23,7 +23,7 @@ from selfprivacy_api.services import get_service_by_id
from selfprivacy_api.backup.tasks import (
start_backup,
restore_snapshot,
set_autobackup_quotas,
prune_autobackup_snapshots,
)
from selfprivacy_api.backup.jobs import add_backup_job, add_restore_job
@ -116,8 +116,9 @@ class BackupMutations:
)
try:
# this is async and can fail with only a job to report the error
set_autobackup_quotas(quotas, job)
Backups.set_autobackup_quotas(quotas)
# this task is async and can fail with only a job to report the error
prune_autobackup_snapshots(job)
return GenericBackupConfigReturn(
success=True,
message="",

View File

@ -651,6 +651,7 @@ def test_too_many_auto(backups, dummy_service):
# Retroactivity
quota.last = 1
Backups.set_autobackup_quotas(quota)
Backups.prune_all_autosnaps()
snaps = Backups.get_snapshots(dummy_service)
assert len(snaps) == 1