Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 304
Reinstates move as an async task#2741
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
Merged
+60
−6
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
10 changes: 10 additions & 0 deletions
10 contentcuration/contentcuration/frontend/shared/data/resources.js
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 |
|---|---|---|
| @@ -10,6 +10,7 @@ | ||
| from django.core.cache import cache | ||
| from django.core.mail import EmailMessage | ||
| from django.db import IntegrityError | ||
| from django.db.utils import OperationalError | ||
| from django.template.loader import render_to_string | ||
| from django.utils import translation | ||
| from django.utils.translation import ugettext as _ | ||
| @@ -22,6 +23,7 @@ | ||
| from contentcuration.utils.csv_writer import write_user_csv | ||
| from contentcuration.utils.nodes import generate_diff | ||
| from contentcuration.utils.publish import publish_channel | ||
| from contentcuration.utils.sentry import report_exception | ||
| from contentcuration.utils.sync import sync_channel | ||
| from contentcuration.utils.user import CACHE_USER_STORAGE_KEY | ||
| from contentcuration.viewsets.sync.constants import CHANNEL | ||
| @@ -56,6 +58,39 @@ | ||
| # runs the management command 'exportchannel' async through celery | ||
| @task(bind=True, name="move_nodes_task") | ||
| def move_nodes_task( | ||
| self, | ||
| user_id, | ||
| channel_id, | ||
| target_id, | ||
| node_id, | ||
| position="last-child", | ||
| ): | ||
| node = ContentNode.objects.get(id=node_id) | ||
| target = ContentNode.objects.get(id=target_id) | ||
| moved = False | ||
| attempts = 0 | ||
| try: | ||
| while not moved and attempts < 10: | ||
| try: | ||
| node.move_to( | ||
| target, | ||
| position, | ||
| ) | ||
| moved = True | ||
| except OperationalError as e: | ||
| if "deadlock detected" in e.args[0]: | ||
| pass | ||
| else: | ||
| raise | ||
| except Exception as e: | ||
| report_exception(e) | ||
| return {"changes": [generate_update_event(node.pk, CONTENTNODE, {"parent": node.parent_id})]} | ||
kollivier marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| @task(bind=True, name="duplicate_nodes_task") | ||
| def duplicate_nodes_task( | ||
| self, | ||
| @@ -212,6 +247,7 @@ def calculate_user_storage_task(user_id): | ||
| type_mapping = { | ||
| "duplicate-nodes": {"task": duplicate_nodes_task, "progress_tracking": True}, | ||
| "move-nodes": {"task": move_nodes_task, "progress_tracking": False}, | ||
| "export-channel": {"task": export_channel_task, "progress_tracking": True}, | ||
| "sync-channel": {"task": sync_channel_task, "progress_tracking": True}, | ||
| "get-node-diff": {"task": generatenodediff_task, "progress_tracking": False}, | ||
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 |
|---|---|---|
| @@ -676,12 +676,20 @@ def move(self, pk, target=None, position=None): | ||
| try: | ||
| target, position = self.validate_targeting_args(target, position) | ||
| try: | ||
| contentnode.move_to(target, position) | ||
| except ValueError: | ||
| raise ValidationError( | ||
| "Invalid position argument specified: {}".format(position) | ||
| ) | ||
| channel_id = target.channel_id | ||
| task_args = { | ||
| "user_id": self.request.user.id, | ||
| "channel_id": channel_id, | ||
| "node_id": contentnode.id, | ||
| "target_id": target.id, | ||
| "position": position, | ||
| } | ||
| task, task_info = create_async_task( | ||
| "move-nodes", self.request.user, **task_args | ||
| ) | ||
kollivier marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| return ( | ||
| None, | ||
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.
Hmm i'm not familiar with this system, but does this basically ensure we delete any move tasks once theyre done in some form?
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.
Yeah, pretty much - we are using the tasks as a messenger format pretty much to revert the move if it fails, but after that we can just auto delete it.