Skip to content

Commit

Permalink
OpenConceptLab/ocl_issues#1814 | moving changelog/diff to async task
Browse files Browse the repository at this point in the history
  • Loading branch information
snyaggarwal committed May 2, 2024
1 parent f8e8464 commit 98957cb
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
8 changes: 8 additions & 0 deletions core/common/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -761,3 +761,11 @@ def resolve_url_registry_entries(repo_id, repo_type):
@app.task(ignore_result=True)
def expire_old_celery_tasks():
Task.objects.filter(updated_at__lt=timezone.now() - timezone.timedelta(days=7)).delete()


@app.task
def source_version_compare(version1_uri, version2_uri, is_changelog, verbosity):
from core.sources.models import Source
version1 = Source.objects.get(uri=version1_uri)
version2 = Source.objects.get(uri=version2_uri)
return Source.changelog(version1, version2) if is_changelog else Source.compare(version1, version2, verbosity)
12 changes: 7 additions & 5 deletions core/sources/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
page_param, verbose_param, include_retired_param, updated_since_param, include_facets_header, compress_header, \
canonical_url_param
from core.common.tasks import export_source, index_source_concepts, index_source_mappings, delete_source, \
generate_source_resources_checksums
generate_source_resources_checksums, source_version_compare
from core.common.utils import parse_boolean_query_param, compact_dict_by_values, to_parent_uri, get_truthy_values
from core.common.views import BaseAPIView, BaseLogoView, ConceptContainerExtraRetrieveUpdateDestroyView
from core.sources.constants import DELETE_FAILURE, DELETE_SUCCESS, VERSION_ALREADY_EXISTS
Expand Down Expand Up @@ -603,7 +603,7 @@ def post(self, request, **kwargs):
raise Http405()


class SourceVersionComparisonView(BaseAPIView): # pragma: no cover
class SourceVersionComparisonView(BaseAPIView, TaskMixin): # pragma: no cover
permission_classes = (IsAuthenticated, CanViewConceptDictionaryVersion)
swagger_schema = None

Expand All @@ -624,6 +624,8 @@ def post(self, _):
except: # pylint: disable=bare-except
verbosity = 0
is_changelog = self.request.query_params.get('changelog', False) in get_truthy_values()
if is_changelog:
return Response(Source.changelog(version1, version2))
return Response(Source.compare(version1, version2, verbosity))
result = self.perform_task(
source_version_compare, (version1.uri, version2.uri, is_changelog, verbosity))
if isinstance(result, Response):
return result
return Response(result)

0 comments on commit 98957cb

Please sign in to comment.