mirror of
https://git.selfprivacy.org/SelfPrivacy/selfprivacy-rest-api.git
synced 2024-11-25 21:41:27 +00:00
feature(backups): global init instead of per-service
This commit is contained in:
parent
e7683352cd
commit
bdae6cfb75
|
@ -229,19 +229,17 @@ class Backups:
|
|||
if service is not None:
|
||||
repo_name = service.get_id()
|
||||
|
||||
Backups.provider().backuper.init(repo_name)
|
||||
if service is not None:
|
||||
Storage.mark_as_init(service)
|
||||
Backups.provider().backuper.init()
|
||||
Storage.mark_as_init()
|
||||
|
||||
@staticmethod
|
||||
def is_initted(service: Service) -> bool:
|
||||
repo_name = service.get_id()
|
||||
if Storage.has_init_mark(service):
|
||||
def is_initted() -> bool:
|
||||
if Storage.has_init_mark():
|
||||
return True
|
||||
|
||||
initted = Backups.provider().backuper.is_initted(repo_name)
|
||||
initted = Backups.provider().backuper.is_initted()
|
||||
if initted:
|
||||
Storage.mark_as_init(service)
|
||||
Storage.mark_as_init()
|
||||
return True
|
||||
|
||||
return False
|
||||
|
|
|
@ -145,7 +145,7 @@ class ResticBackuper(AbstractBackuper):
|
|||
service_name=repo_name,
|
||||
)
|
||||
|
||||
def init(self, repo_name):
|
||||
def init(self):
|
||||
init_command = self.restic_command(
|
||||
"init",
|
||||
)
|
||||
|
@ -159,7 +159,7 @@ class ResticBackuper(AbstractBackuper):
|
|||
if not "created restic repository" in output:
|
||||
raise ValueError("cannot init a repo: " + output)
|
||||
|
||||
def is_initted(self, repo_name: str) -> bool:
|
||||
def is_initted(self) -> bool:
|
||||
command = self.restic_command(
|
||||
"check",
|
||||
"--json",
|
||||
|
|
|
@ -160,13 +160,11 @@ class Storage:
|
|||
return provider_model
|
||||
|
||||
@staticmethod
|
||||
def has_init_mark(service: Service) -> bool:
|
||||
repo_name = service.get_id()
|
||||
if redis.exists(REDIS_INITTED_CACHE_PREFIX + repo_name):
|
||||
def has_init_mark() -> bool:
|
||||
if redis.exists(REDIS_INITTED_CACHE_PREFIX):
|
||||
return True
|
||||
return False
|
||||
|
||||
@staticmethod
|
||||
def mark_as_init(service: Service):
|
||||
repo_name = service.get_id()
|
||||
redis.set(REDIS_INITTED_CACHE_PREFIX + repo_name, 1)
|
||||
def mark_as_init():
|
||||
redis.set(REDIS_INITTED_CACHE_PREFIX, 1)
|
||||
|
|
|
@ -120,7 +120,7 @@ def test_select_backend():
|
|||
|
||||
|
||||
def test_file_backend_init(file_backup):
|
||||
file_backup.backuper.init("somerepo")
|
||||
file_backup.backuper.init()
|
||||
|
||||
|
||||
def test_backup_simple_file(raw_dummy_service, file_backup):
|
||||
|
@ -130,7 +130,7 @@ def test_backup_simple_file(raw_dummy_service, file_backup):
|
|||
assert file_backup is not None
|
||||
|
||||
name = service.get_id()
|
||||
file_backup.backuper.init(name)
|
||||
file_backup.backuper.init()
|
||||
|
||||
|
||||
def test_backup_service(dummy_service, backups):
|
||||
|
@ -217,11 +217,11 @@ def test_sizing(backups, dummy_service):
|
|||
|
||||
|
||||
def test_init_tracking(backups, raw_dummy_service):
|
||||
assert Backups.is_initted(raw_dummy_service) is False
|
||||
assert Backups.is_initted() is False
|
||||
|
||||
Backups.init_repo(raw_dummy_service)
|
||||
Backups.init_repo()
|
||||
|
||||
assert Backups.is_initted(raw_dummy_service) is True
|
||||
assert Backups.is_initted() is True
|
||||
|
||||
|
||||
def finished_jobs():
|
||||
|
@ -414,21 +414,21 @@ def test_snapshots_caching(backups, dummy_service):
|
|||
|
||||
# Storage
|
||||
def test_init_tracking_caching(backups, raw_dummy_service):
|
||||
assert Storage.has_init_mark(raw_dummy_service) is False
|
||||
assert Storage.has_init_mark() is False
|
||||
|
||||
Storage.mark_as_init(raw_dummy_service)
|
||||
Storage.mark_as_init()
|
||||
|
||||
assert Storage.has_init_mark(raw_dummy_service) is True
|
||||
assert Backups.is_initted(raw_dummy_service) is True
|
||||
assert Storage.has_init_mark() is True
|
||||
assert Backups.is_initted() is True
|
||||
|
||||
|
||||
# Storage
|
||||
def test_init_tracking_caching2(backups, raw_dummy_service):
|
||||
assert Storage.has_init_mark(raw_dummy_service) is False
|
||||
assert Storage.has_init_mark() is False
|
||||
|
||||
Backups.init_repo(raw_dummy_service)
|
||||
Backups.init_repo()
|
||||
|
||||
assert Storage.has_init_mark(raw_dummy_service) is True
|
||||
assert Storage.has_init_mark() is True
|
||||
|
||||
|
||||
# Storage
|
||||
|
|
Loading…
Reference in a new issue