mirror of
https://git.selfprivacy.org/SelfPrivacy/selfprivacy-rest-api.git
synced 2024-11-24 13:01:28 +00:00
refactor(backups): only async snapshot trimming
This commit is contained in:
parent
e0b04217cd
commit
d549e29304
|
@ -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)
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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="",
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
Loading…
Reference in a new issue