Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Retry on server busy #126

Merged
merged 2 commits into from
Jul 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions pyezviz/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -732,6 +732,9 @@ def get_storage_status(self, serial: str, max_retries: int = 0) -> Any:
) from err

if json_output["resultCode"] != "0":
if json_output["resultCode"] == "-1":
_LOGGER.warning("Server busy, retrying %s", max_retries)
return self.get_storage_status(serial, max_retries + 1)
raise PyEzvizError(
f"Could not get device storage status: Got {json_output})"
)
Expand Down Expand Up @@ -944,6 +947,9 @@ def reboot_camera(
) from err

if json_output["resultCode"] != "0":
if json_output["resultCode"] == "-1":
_LOGGER.warning("Server busy, retrying %s", max_retries)
return self.reboot_camera(serial, delay, operation, max_retries + 1)
raise PyEzvizError(f"Could not reboot device {json_output})")

return True
Expand Down Expand Up @@ -1207,6 +1213,9 @@ def get_cam_key(
raise EzvizAuthVerificationCode(f"MFA code required: Got {json_output})")

if json_output["resultCode"] != "0":
if json_output["resultCode"] == "-1":
_LOGGER.warning("Server busy, retrying %s", max_retries)
return self.get_cam_key(serial, smscode, max_retries + 1)
raise PyEzvizError(
f"Could not get camera encryption key: Got {json_output})"
)
Expand Down Expand Up @@ -1248,6 +1257,9 @@ def create_panoramic(self, serial: str, max_retries: int = 0) -> Any:
) from err

if json_output["resultCode"] != "0":
if json_output["resultCode"] == "-1":
_LOGGER.warning("Server busy, retrying %s", max_retries)
return self.create_panoramic(serial, max_retries + 1)
raise PyEzvizError(
f"Could not send command to create panoramic photo: Got {json_output})"
)
Expand Down Expand Up @@ -1289,6 +1301,9 @@ def return_panoramic(self, serial: str, max_retries: int = 0) -> Any:
) from err

if json_output["resultCode"] != "0":
if json_output["resultCode"] == "-1":
_LOGGER.warning("Server busy, retrying %s", max_retries)
return self.return_panoramic(serial, max_retries + 1)
raise PyEzvizError(f"Could retrieve panoramic photo: Got {json_output})")

return json_output
Expand Down Expand Up @@ -1491,6 +1506,11 @@ def api_set_defence_schedule(
) from err

if json_output["resultCode"] != "0":
if json_output["resultCode"] == "-1":
_LOGGER.warning("Server busy, retrying %s", max_retries)
return self.api_set_defence_schedule(
serial, schedule, enable, max_retries + 1
)
raise PyEzvizError(f"Could not set the schedule: Got {json_output})")

return True
Expand Down Expand Up @@ -1683,6 +1703,11 @@ def detection_sensibility(
raise PyEzvizError("Could not decode response:" + str(err)) from err

if response_json["resultCode"] != "0":
if response_json["resultCode"] == "-1":
_LOGGER.warning("Server busy, retrying %s", max_retries)
return self.detection_sensibility(
serial, sensibility, type_value, max_retries + 1
)
raise PyEzvizError(
f"Unable to set detection sensibility. Got: {response_json}"
)
Expand Down Expand Up @@ -1726,6 +1751,11 @@ def get_detection_sensibility(
raise PyEzvizError("Could not decode response:" + str(err)) from err

if response_json["resultCode"] != "0":
if response_json["resultCode"] == "-1":
_LOGGER.warning("Server busy, retrying %s", max_retries)
return self.get_detection_sensibility(
serial, type_value, max_retries + 1
)
raise PyEzvizError(
f"Unable to get detection sensibility. Got: {response_json}"
)
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

setuptools.setup(
name='pyezviz',
version="0.2.1.6",
version="0.2.1.7",
license='Apache Software License 2.0',
author='Pierre Ourdouille',
author_email='[email protected]',
Expand Down