Skip to content
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

Merge unstable into gsoc/transcription #4334

Merged
merged 10 commits into from
Nov 9, 2023
39 changes: 14 additions & 25 deletions contentcuration/contentcuration/viewsets/sync/endpoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
bulk creates, updates, and deletes.
"""
from celery import states
from django.db.models import Exists
from django.db.models import OuterRef
from django.db.models import Q
from django_celery_results.models import TaskResult
from django_cte import CTEQuerySet
from django_cte import With
from rest_framework.authentication import SessionAuthentication
from rest_framework.permissions import IsAuthenticated
from rest_framework.response import Response
Expand Down Expand Up @@ -126,38 +126,27 @@ def return_changes(self, request, channel_revs):
return {"changes": changes, "errors": errors, "successes": successes}

def return_tasks(self, request, channel_revs):
custom_task_objects = CustomTaskMetadata.objects.filter(
channel_id__in=channel_revs.keys()
).annotate(
has_matching_task=Exists(
TaskResult.objects.filter(
task_id=OuterRef('task_id'),
status__in=[states.STARTED, states.FAILURE],
).exclude(
custom_task_cte = With(CustomTaskMetadata.objects.filter(channel_id__in=channel_revs.keys()))
task_result_querySet = CTEQuerySet(model=TaskResult)
query = custom_task_cte.join(task_result_querySet, task_id=custom_task_cte.col.task_id)\
.with_cte(custom_task_cte)\
.filter(status__in=[states.STARTED, states.FAILURE],)\
.exclude(
task_name__in=[apply_channel_changes_task.name, apply_user_changes_task.name]
)
)
).filter(
has_matching_task=True
).annotate(
progress=custom_task_cte.col.progress,
channel_id=custom_task_cte.col.channel_id,
)

response_payload = {
"tasks": [],
}

for custom_task in custom_task_objects:
task_data = {
"task_id": custom_task.task_id,
"task_name": custom_task.task_name,
"traceback": custom_task.task_result.traceback,
"progress": custom_task.progress,
"channel_id": custom_task.channel_id,
"status": custom_task.task_result.status,
if query.exists():
response_payload = {
"tasks": query.values("task_id", "task_name", "traceback", "progress", "channel_id", "status"),
}

# Add the task data to the response_payload
response_payload["tasks"].append(task_data)

return response_payload

def post(self, request):
Expand Down
2 changes: 1 addition & 1 deletion requirements-dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ customizable-django-profiler @ git+https://github.com/someshchaturvedi/customiza
# via -r requirements-dev.in
distlib==0.3.1
# via virtualenv
django==3.2.19
django==3.2.23
# via
# -c requirements.txt
# django-debug-toolbar
Expand Down
2 changes: 1 addition & 1 deletion requirements.in
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ celery==5.2.7
redis
pathlib
python-postmark==0.5.8
Django==3.2.19
Django==3.2.23
django-webpack-loader==0.7.0
google-cloud-error-reporting
google-cloud-storage
Expand Down
3 changes: 2 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ click-repl==0.2.0
# via celery
confusable-homoglyphs==3.2.0
# via django-registration
django==3.2.19
django==3.2.23
# via
# -r requirements.in
# django-bulk-update
Expand Down Expand Up @@ -103,6 +103,7 @@ future==0.18.3
# via -r requirements.in
google-api-core[grpc]==1.27.0
# via
# google-api-core
# google-cloud-core
# google-cloud-error-reporting
# google-cloud-kms
Expand Down