mirror of
https://git.selfprivacy.org/SelfPrivacy/selfprivacy-rest-api.git
synced 2025-03-11 09:03:50 +00:00
refactor(backups): a better backup-related service timeout error
This commit is contained in:
parent
72535f8655
commit
de52dffdda
1 changed files with 16 additions and 10 deletions
|
@ -284,17 +284,23 @@ class StoppedService:
|
||||||
def __enter__(self) -> Service:
|
def __enter__(self) -> Service:
|
||||||
self.original_status = self.service.get_status()
|
self.original_status = self.service.get_status()
|
||||||
if self.original_status not in [ServiceStatus.INACTIVE, ServiceStatus.FAILED]:
|
if self.original_status not in [ServiceStatus.INACTIVE, ServiceStatus.FAILED]:
|
||||||
self.service.stop()
|
try:
|
||||||
wait_until_true(
|
self.service.stop()
|
||||||
lambda: self.service.get_status() == ServiceStatus.INACTIVE,
|
wait_until_true(
|
||||||
timeout_sec=DEFAULT_START_STOP_TIMEOUT,
|
lambda: self.service.get_status() == ServiceStatus.INACTIVE,
|
||||||
)
|
timeout_sec=DEFAULT_START_STOP_TIMEOUT,
|
||||||
|
)
|
||||||
|
except TimeoutError as e:
|
||||||
|
raise TimeoutError(f"timed out waiting for {self.service.get_display_name()} to stop")
|
||||||
return self.service
|
return self.service
|
||||||
|
|
||||||
def __exit__(self, type, value, traceback):
|
def __exit__(self, type, value, traceback):
|
||||||
if self.original_status in [ServiceStatus.ACTIVATING, ServiceStatus.ACTIVE]:
|
if self.original_status in [ServiceStatus.ACTIVATING, ServiceStatus.ACTIVE]:
|
||||||
self.service.start()
|
try:
|
||||||
wait_until_true(
|
self.service.start()
|
||||||
lambda: self.service.get_status() == ServiceStatus.ACTIVE,
|
wait_until_true(
|
||||||
timeout_sec=DEFAULT_START_STOP_TIMEOUT,
|
lambda: self.service.get_status() == ServiceStatus.ACTIVE,
|
||||||
)
|
timeout_sec=DEFAULT_START_STOP_TIMEOUT,
|
||||||
|
)
|
||||||
|
except TimeoutError as e:
|
||||||
|
raise TimeoutError(f"timed out waiting for {self.service.get_display_name()} to start")
|
||||||
|
|
Loading…
Add table
Reference in a new issue