-
Notifications
You must be signed in to change notification settings - Fork 0
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
chore: Fix background tasks blocking UI #797
Merged
RisingOrange
merged 11 commits into
main
from
chore/specify-uses-collection-false-for-background-tasks
Nov 13, 2023
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
958fcec
Use QueryOp.without_collection for media download task
RisingOrange 42e4fb4
Use QueryOp.without_collection for media upload task
RisingOrange cda3139
Use QueryOp.without_collection for tag group validation task
RisingOrange 1c05600
Add `AddonQueryOp` and use it instead of `QueryOp`
RisingOrange 64f33f3
Use AddonQueryOp.without_collection in errors.py
RisingOrange 4e5526a
Replace usage of QueryOp with AddonQueryOp
RisingOrange 24dbd76
Merge branch 'main' into chore/specify-uses-collection-false-for-back…
RisingOrange 34e17b8
Merge branch 'main' into chore/specify-uses-collection-false-for-back…
RisingOrange c32218c
Add tests
RisingOrange 67a8198
Merge branch 'main' into chore/specify-uses-collection-false-for-back…
RisingOrange 2b78b8c
Merge branch 'main' into chore/specify-uses-collection-false-for-back…
RisingOrange 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 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 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 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 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 |
---|---|---|
@@ -0,0 +1,31 @@ | ||
from aqt.operations import QueryOp | ||
|
||
from ...settings import ANKI_MINOR | ||
|
||
|
||
class AddonQueryOp(QueryOp): | ||
"""A subclass of aqt.operations.QueryOp that is tailored for the AnkiHub add-on.""" | ||
|
||
def __init__(self, *args, **kwargs): | ||
super().__init__(*args, **kwargs) | ||
|
||
# The default behavior of the QueryOp class on a failure is to show the exception to the user. | ||
# However we want to raise the exception so that our central error handler can handle it. | ||
self._failure = _on_failure | ||
|
||
def without_collection(self): | ||
"""The QueryOp class doesn't have a without_collection method on Anki versions before 23.10. | ||
We are setting this to be a no-op for backwards compatibility. | ||
It's fine for this to be a no-op, because without_collection is used to allow | ||
background tasks to run in parallel. On previous Anki versions background tasks were | ||
already running in parallel, so there is no need to do anything. | ||
This way we can use the same code for all Anki versions. | ||
""" | ||
if ANKI_MINOR < 231000: | ||
return self | ||
|
||
return super().without_collection() | ||
|
||
|
||
def _on_failure(exception: Exception) -> None: | ||
raise exception |
This file contains 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 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
Oops, something went wrong.
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.
🌱 Since this is a value used in multiple places, maybe is a good idea to store this in a constant that can be imported by different modules.
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.
@pedroven
What do you mean?
ANKI_MINOR
is already a constant (which is defined inankihub.settings
.Here's a related PR, which renames the constant to
ANKI_INT_VERSION
make the name more accurate btw: #805There 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.
I wasn't talking about the
ANKI_MINOR
, I'm talking about the value 231000. This value is kind of a magic number, without context is almost impossible to know why this value is important. So I'm suggesting changing this value to a constant that adds some context.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.
@pedroven Oh that makes sense! Created a PR for it: #806