-
Notifications
You must be signed in to change notification settings - Fork 13
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
Use asyncio to speed up cloud identification #12
Conversation
For some unknown reason, I get the below error on my machine(MacOS x86) during
I tried different Python versions (3.7, 3.8, 3.9), but the error doesn't go away. Update: The error occurs in |
cloud_detect/__init__.py
Outdated
|
||
if tasks: | ||
await cancel_unfinished_tasks() | ||
return 'timeout' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the code runs in a non-supported cloud environment or in local, the response is usually going to betimeout
because almost all the cloud provider urls take more than 5s to respond.
My original motivation for adding timeout
in addition to unknown
and cloud-name was being explicit, but now I feel it makes the api more complicated for the user. I am mulling over to remove timeout
and replace it with unknown
. @dgzlopes Let me know your thoughts on this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In my latest commits I have set timeout
's default value as None
and removed "timeout" as a response.
So, by default, provider
will take all its time to determine the cloud provider. In my local, it took around 1 min 15s to return unknown
.
cloud_detect/__init__.py
Outdated
return result | ||
|
||
|
||
async def async_provider(timeout=TIMEOUT): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the user code is async, then they should use this api instead of provider
. I will mention the same in docstrings.
@dgzlopes Test cases are failing for Python 3.5 because the library for mocking api responses - |
@dgzlopes How important is Python 3.5 support? It's officially retired - https://endoflife.date/python. |
Not important @kshivakumar :D Feel free to drop it! |
55ffdb9
to
0e202dd
Compare
I'll review the PR at the end of the week (I've scheduled it on my personal calendar). Sorry for my slow pace 😄 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks again for the PR! LGTM :)
The only thing, while running tox locally, the pre-commit hook step did some fixes on setup.py
(re-ordering Python import). Do you mind committing those?
Thanks again!
Signed-off-by: kshivakumar <kshivakumar@outlook.com>
Signed-off-by: kshivakumar <kshivakumar@outlook.com>
Signed-off-by: kshivakumar <kshivakumar@outlook.com>
Signed-off-by: kshivakumar <kshivakumar@outlook.com>
Signed-off-by: kshivakumar <kshivakumar@outlook.com>
Signed-off-by: kshivakumar <kshivakumar@outlook.com>
17fbd7a
to
7ee9b69
Compare
@dgzlopes Fixed it and also updated README. |
@dgzlopes Can we merge this if there are no further issues? |
Sorry for the delay! I had a mess on my GH notifications :( Merged. I'll cut a new release. |
Implements #11
Uses
asyncio
to check all the cloud providers concurrently and returns back a response as soon as the cloud provider is detected.Important changes:
requests
withaiohttp
in the dependenciesidentifier
class variable to each*Provider
classSUPPORTED_PROVIDERS
api - it's a tuple ofidentifier
values of each Provider classI manually tested the changes in Azure and GCP, it's working fine and the response comes back within a second.