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

Fix: add throttle for requests #9

Merged
merged 1 commit into from
Jun 9, 2024
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
11 changes: 11 additions & 0 deletions Scripts/cli/src/client/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
from ..dto import SettingsTypeCompound
from ..dto import SetSettingsDto

from ..tools import perform_request_await


class Client:
"""Represents client used to connect to remote device via serial port."""
Expand Down Expand Up @@ -51,6 +53,9 @@ def __send_data_bus_request_content(self, type: DataBus.DataType) -> Response.Re
data = request_container.SerializeToString()

self.connection.write(data_length)

perform_request_await()

self.connection.write(data)

result_length_raw = self.connection.read(3)
Expand Down Expand Up @@ -122,6 +127,9 @@ def __send_info_bus_request_content(self, type: InfoBus.InfoType) -> Response.Re
data = request_container.SerializeToString()

self.connection.write(data_length)

perform_request_await()

self.connection.write(data)

result_length_raw = self.connection.read(3)
Expand Down Expand Up @@ -193,6 +201,9 @@ def __send_settings_bus_request_content(self, type: SettingsBus.SettingsType) ->
data = request_container.SerializeToString()

self.connection.write(data_length)

perform_request_await()

self.connection.write(data)

result_length_raw = self.connection.read(3)
Expand Down
4 changes: 3 additions & 1 deletion Scripts/cli/src/tools/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
from .prettifier import print_output
from .prettifier import print_output

from .throttle import perform_request_await
10 changes: 10 additions & 0 deletions Scripts/cli/src/tools/throttle.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import time

# Represents throttle request duration time.
THROTTLE_REQUEST_DURATION: float = 0.3


def perform_request_await() -> None:
"""Performs throttle request operation."""

time.sleep(THROTTLE_REQUEST_DURATION)
Loading