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 small bugs in the async client #68

Merged
merged 1 commit into from
Sep 12, 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
37 changes: 26 additions & 11 deletions firecrest/AsyncClient.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,10 @@ async def wrapper(*args, **kwargs):
f"Rate limit in `{microservice}` is reached, next "
f"request will be possible in {reset} sec"
)
client._next_request_ts[microservice] = (
time.time() + reset
)
retry_time = time.time() + reset
if retry_time > client._next_request_ts[microservice]:
client._next_request_ts[microservice] = retry_time

resp = await func(*args, **kwargs)
num_retries += 1

Expand Down Expand Up @@ -762,8 +763,9 @@ async def head(
self,
machine: str,
target_path: str,
bytes: Optional[int] = None,
lines: Optional[int] = None,
bytes: Optional[str] = None,
lines: Optional[str] = None,
skip_ending: Optional[bool] = False,
) -> str:
"""Display the beginning of a specified file.
By default 10 lines will be returned.
Expand All @@ -773,23 +775,30 @@ async def head(

:param machine: the machine name where the filesystem belongs to
:param target_path: the absolute target path
:param lines: the number of lines to be displayed
:param bytes: the number of bytes to be displayed
:param lines: the number of lines to be displayed
:param skip_ending: the output will be the whole file, without the last NUM bytes/lines of each file. NUM should be specified in the respective argument through `bytes` or `lines`. Equivalent to passing -NUM to the `head` command.
:calls: GET `/utilities/head`
"""
resp = await self._get_request(
endpoint="/utilities/head",
additional_headers={"X-Machine-Name": machine},
params={"targetPath": target_path, "lines": lines, "bytes": bytes},
params={
"targetPath": target_path,
"lines": lines,
"bytes": bytes,
"skip_ending": skip_ending,
},
)
return self._json_response([resp], 200)["output"]

async def tail(
self,
machine: str,
target_path: str,
bytes: Optional[int] = None,
lines: Optional[int] = None,
bytes: Optional[str] = None,
lines: Optional[str] = None,
skip_beginning: Optional[bool] = False,
) -> str:
"""Display the last part of a specified file.
By default 10 lines will be returned.
Expand All @@ -799,14 +808,20 @@ async def tail(

:param machine: the machine name where the filesystem belongs to
:param target_path: the absolute target path
:param lines: the number of lines to be displayed
:param bytes: the number of bytes to be displayed
:param lines: the number of lines to be displayed
:param skip_beginning: the output will start with byte/line NUM of each file. NUM should be specified in the respective argument through `bytes` or `lines`. Equivalent to passing +NUM to the `tail` command.
:calls: GET `/utilities/head`
"""
resp = await self._get_request(
endpoint="/utilities/tail",
additional_headers={"X-Machine-Name": machine},
params={"targetPath": target_path, "lines": lines, "bytes": bytes},
params={
"targetPath": target_path,
"lines": lines,
"bytes": bytes,
"skip_beginning": skip_beginning,
},
)
return self._json_response([resp], 200)["output"]

Expand Down
4 changes: 2 additions & 2 deletions firecrest/BasicClient.py
Original file line number Diff line number Diff line change
Expand Up @@ -677,8 +677,8 @@ def head(

:param machine: the machine name where the filesystem belongs to
:param target_path: the absolute target path
:param lines: the number of lines to be displayed
:param bytes: the number of bytes to be displayed
:param lines: the number of lines to be displayed
:param skip_ending: the output will be the whole file, without the last NUM bytes/lines of each file. NUM should be specified in the respective argument through `bytes` or `lines`. Equivalent to passing -NUM to the `head` command.
:calls: GET `/utilities/head`
"""
Expand Down Expand Up @@ -710,8 +710,8 @@ def tail(

:param machine: the machine name where the filesystem belongs to
:param target_path: the absolute target path
:param lines: the number of lines to be displayed
:param bytes: the number of bytes to be displayed
:param lines: the number of lines to be displayed
:param skip_beginning: the output will start with byte/line NUM of each file. NUM should be specified in the respective argument through `bytes` or `lines`. Equivalent to passing +NUM to the `tail` command.
:calls: GET `/utilities/head`
"""
Expand Down
Loading