-
Notifications
You must be signed in to change notification settings - Fork 21
Async mode support #31
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
Open
michelts
wants to merge
10
commits into
ConvertAPI:master
Choose a base branch
from
michelts:async-mode-support
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
78416a0
Add support for async mode operation
michelts 6f1b901
Test also polling of invalid url
michelts 2f9fd3c
Avoid a JSONDecodeError when polling too earlier
michelts 33bfe35
Use exponential growing retry timeout
michelts 9ae5d5a
Use an explicit exception to tell the conversion is in progress
michelts 2d4108c
Explicit test a blank response instead of any non-json response
michelts 118e8b6
Remove unnecessary import
michelts 9930a16
Pack the helper function inside the test class
michelts 27b517f
Do not raise AsyncConversionInProgress for regular requests
michelts cccb50b
Remove unnecessary import
michelts File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,10 +1,25 @@ | ||
| import convertapi | ||
|
|
||
| from .task import Task | ||
| from .result import Result | ||
| from .exceptions import AsyncConversionInProgress | ||
|
|
||
| def convert(to_format, params, from_format = None, timeout = None): | ||
| task = Task(from_format, to_format, params, timeout = timeout) | ||
| return task.run() | ||
|
|
||
|
|
||
| def user(timeout = None): | ||
| return convertapi.client.get('user', timeout = timeout) | ||
|
|
||
|
|
||
| def async_convert(to_format, params, from_format = None, timeout = None): | ||
| task = Task(from_format, to_format, params, timeout = timeout, is_async = True) | ||
| return task.run() | ||
|
|
||
|
|
||
| def async_poll(job_id): | ||
| response = convertapi.client.get('async/job/%s' % job_id) | ||
| if not response: | ||
| raise AsyncConversionInProgress | ||
| return Result(response) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
This is to solve a problem mentioned in issue #21: while the conversion is in progress, it seems the response from the server is a 202 Accepted with a blank response.
In the tests, the very first request after the async conversion has a status code 200 and blank content. The second request would have a status 202, as well as the subsequent requests until a 200 response with the expected result.
That's why I'm not testing for a 202 status code.
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.
Notice this would raise a JSONDecodeError for any get request that doesn't have a JSON response, and I don't want to fail with an AsyncConversionInProgress error for any request. This way, I'm returning None, and only on the async_poll function I will check for the empty response and raise the exception accordingly.