mirror of
https://git.selfprivacy.org/SelfPrivacy/selfprivacy-rest-api.git
synced 2025-01-11 18:39:30 +00:00
fix(backups): do not autobackup disabled services
This commit is contained in:
parent
0ccb85d5cc
commit
7ec62a8f79
|
@ -731,11 +731,14 @@ class Backups:
|
||||||
def is_time_to_backup_service(service: Service, time: datetime):
|
def is_time_to_backup_service(service: Service, time: datetime):
|
||||||
"""Returns True if it is time to back up a service"""
|
"""Returns True if it is time to back up a service"""
|
||||||
period = Backups.autobackup_period_minutes()
|
period = Backups.autobackup_period_minutes()
|
||||||
if not service.can_be_backed_up():
|
|
||||||
return False
|
|
||||||
if period is None:
|
if period is None:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
if not service.is_enabled():
|
||||||
|
return False
|
||||||
|
if not service.can_be_backed_up():
|
||||||
|
return False
|
||||||
|
|
||||||
last_error = Backups.get_last_backup_error_time(service)
|
last_error = Backups.get_last_backup_error_time(service)
|
||||||
|
|
||||||
if last_error is not None:
|
if last_error is not None:
|
||||||
|
@ -743,8 +746,9 @@ class Backups:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
last_backup = Backups.get_last_backed_up(service)
|
last_backup = Backups.get_last_backed_up(service)
|
||||||
|
|
||||||
|
# Queue a backup immediately if there are no previous backups
|
||||||
if last_backup is None:
|
if last_backup is None:
|
||||||
# queue a backup immediately if there are no previous backups
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
if time > last_backup + timedelta(minutes=period):
|
if time > last_backup + timedelta(minutes=period):
|
||||||
|
|
|
@ -889,7 +889,7 @@ def backuppable_services() -> list[Service]:
|
||||||
return [service for service in get_all_services() if service.can_be_backed_up()]
|
return [service for service in get_all_services() if service.can_be_backed_up()]
|
||||||
|
|
||||||
|
|
||||||
def test_services_to_back_up(backups, dummy_service):
|
def test_services_to_autobackup(backups, dummy_service):
|
||||||
backup_period = 13 # minutes
|
backup_period = 13 # minutes
|
||||||
now = datetime.now(timezone.utc)
|
now = datetime.now(timezone.utc)
|
||||||
|
|
||||||
|
@ -911,6 +911,15 @@ def test_services_to_back_up(backups, dummy_service):
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
|
def test_do_not_autobackup_disabled_services(backups, dummy_service):
|
||||||
|
now = datetime.now(timezone.utc)
|
||||||
|
Backups.set_autobackup_period_minutes(3)
|
||||||
|
assert Backups.is_time_to_backup_service(dummy_service, now) is True
|
||||||
|
|
||||||
|
dummy_service.disable()
|
||||||
|
assert Backups.is_time_to_backup_service(dummy_service, now) is False
|
||||||
|
|
||||||
|
|
||||||
def test_autobackup_timer_periods(backups, dummy_service):
|
def test_autobackup_timer_periods(backups, dummy_service):
|
||||||
now = datetime.now(timezone.utc)
|
now = datetime.now(timezone.utc)
|
||||||
backup_period = 13 # minutes
|
backup_period = 13 # minutes
|
||||||
|
|
Loading…
Reference in a new issue