Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
leshchenko1979 committed Mar 23, 2024
2 parents 8906953 + 0f0f813 commit 6e5a94c
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 4 deletions.
16 changes: 13 additions & 3 deletions fast_bitrix24/srh.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,9 +163,7 @@ async def request_attempt(self, method, params=None) -> dict:

logger.debug("Response: %s", json)

request_run_time = json["time"]["operating"]
self.method_throttlers[method].add_request_record(request_run_time)
self.leaky_bucket_throttler.add_request_record()
self.add_throttler_records(method, params, json)

return json

Expand All @@ -175,6 +173,18 @@ async def request_attempt(self, method, params=None) -> dict:

raise

def add_throttler_records(self, method, params: dict, json: dict):
if "result_time" in json:
for cmd_name, cmd_url in params["cmd"].items():
item_method = cmd_url.split("?")[0]
item_time = json["result_time"][cmd_name]
self.method_throttlers[item_method].add_request_record(item_time)
else:
request_run_time = json["time"]["operating"]
self.method_throttlers[method].add_request_record(request_run_time)

self.leaky_bucket_throttler.add_request_record()

def success(self):
"""Увеличить счетчик удачных попыток."""

Expand Down
14 changes: 13 additions & 1 deletion fast_bitrix24/user_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,13 +131,25 @@ def check_special_limitations(self):
stacklevel=get_warning_stack_level(TOP_MOST_LIBRARY_MODULES),
)

if "LIMIT" in self.st_params:
if self.st_params and "LIMIT" in self.st_params:
warnings.warn(
"Bitrix servers don't seem to support the 'LIMIT' parameter.",
UserWarning,
stacklevel=get_warning_stack_level(TOP_MOST_LIBRARY_MODULES),
)

if (
self.st_params
and "SELECT" in self.st_params
and "*" in self.st_params["SELECT"]
):
warnings.warn(
"You are selecting all fields. Beware that this is time-consuming and "
"may lead to penalties from the Bitrix server.",
UserWarning,
stacklevel=get_warning_stack_level(TOP_MOST_LIBRARY_MODULES),
)

return True

async def run(self):
Expand Down

0 comments on commit 6e5a94c

Please sign in to comment.