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

Wrong return type, misleading timeout, and print() statements #30

Open
jgentil opened this issue May 23, 2023 · 0 comments
Open

Wrong return type, misleading timeout, and print() statements #30

jgentil opened this issue May 23, 2023 · 0 comments

Comments

@jgentil
Copy link

jgentil commented May 23, 2023

def check_tx_is_completed(self, tx_id) -> dict:
"""
This function waits for SUBMIT_TIMEOUT*4 (180 by default) seconds to retrieve status of the transaction sent to
Fireblocks. Will stop upon completion / failure.
:param tx_id: Transaction ID from FBKS.
:return: Transaction last status after timeout / completion.
"""
timeout = 0
current_status = self.fb_api_client.get_transaction_by_id(tx_id)[STATUS_KEY]
while current_status not in (
TRANSACTION_STATUS_COMPLETED, TRANSACTION_STATUS_FAILED, TRANSACTION_STATUS_BLOCKED,
TRANSACTION_STATUS_CANCELLED) and timeout < SUBMIT_TIMEOUT:
print(f"TX [{tx_id}] is currently at status - {current_status} {'.' * (timeout % 4)} ",
end="\r")
time.sleep(4)
current_status = self.fb_api_client.get_transaction_by_id(tx_id)[STATUS_KEY]
timeout += 1
print(f"\nTX [{tx_id}] is currently at status - {current_status}")
return current_status

These print statements make it extra difficult for output be properly logged. They should either be done with the logging package or just not at all, since this isn't a presentation layer. In particular, the \r special character to make it look self-erasing ruins my log files.

I'm confused as to why the initial call to Why doesn't the initial POST return an HTTP 202 status to indicate that it wasn't completed, only accepted? Also, SUBMIT_TIMEOUT is actually a retry loop, not a time in seconds, which is misleading. It will stop retrying after SUBMIT_TIMEOUT number of loops, which is guaranteed to be significantly longer than SUBMIT_TIMEOUT*4 since the very minimum amount of time it will take is 4 seconds from the time.sleep(4) statement.

Also this function returns str and not dict

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant