Skip to content

Commit

Permalink
fix: added throttle for requests (#9)
Browse files Browse the repository at this point in the history
  • Loading branch information
YarikRevich authored Jun 9, 2024
1 parent 2ce49ce commit 98f2cfa
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
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)

0 comments on commit 98f2cfa

Please sign in to comment.