Skip to content

Conversation

@alby-m
Copy link
Contributor

@alby-m alby-m commented Mar 23, 2021

Closes: MichalJanik/mergado#7962

Includes:

-added option for requests retrying when specified status codes are obtained from response
-status codes to trigger retry set defaultly to 500,502,503 and 504 (can be changed by spcecifying retry_status_list arg of codes when initializing client)
-number of tries defaultly set to 3 (can be changed by spcecifying tries arg when initializing client)

@alby-m alby-m self-assigned this Mar 23, 2021
@alby-m alby-m requested a review from MatejHamala March 23, 2021 07:53
Copy link
Collaborator

@MatejHamala MatejHamala left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📚 👍 Jsou tam dvě blbosti, který reálně nehrajou roli ale principiálně by je šlo udělat lépe. 🙂

grant_type=None, storage_class=config.TOKEN_STORAGE_CLASS,
token_uri=config.TOKEN_URI, api_uri=config.MERGADO_API_URI):
token_uri=config.TOKEN_URI, api_uri=config.MERGADO_API_URI,
retry_status_list=[500, 502, 503, 504], tries=3):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

V defaultních argumentech (a v podstatě všech pouze read-only proměnných) je vždy lepší používat immutable typy. Tzn mít místo seznamu retry_status_list=[500, 502, 503, 504] použít n-tici retry_status_list=(500, 502, 503, 504). 🙂

Imutable typy jsou v podstatě konstanty a tudíž si je python může při kompilaci natvrdo přeložit do bytekódu, místo toho aby vytvářel muttable objekty na haldě (s kterýma jsou všechny operace náročnější).


def retry_request(make_request, retry_status_list, tries):
for i in range(tries):
wait = 2 ** i
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tohle by šlo hodit až za ten if - většinou to totiž vůbec nebude potřeba počítat. 🙂

@alby-m alby-m force-pushed the requests_retry_session branch from 816ac33 to dba48c0 Compare March 24, 2021 06:45
@alby-m alby-m force-pushed the requests_retry_session branch from dba48c0 to bd024d1 Compare March 24, 2021 11:52
@alby-m alby-m merged commit 2c2ffb0 into master Mar 24, 2021
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

Successfully merging this pull request may close these issues.

3 participants