Skip to content

Commit

Permalink
Kaan feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
yassinsws committed Oct 13, 2024
1 parent 9f144ae commit 481ce45
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 10 deletions.
35 changes: 26 additions & 9 deletions app/web/routers/ingestion_status.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import json
from urllib.parse import unquote

from fastapi import APIRouter, status, Response, Depends
from fastapi.params import Query
from weaviate.collections.classes.filters import Filter

from app.dependencies import TokenValidator
Expand All @@ -9,24 +11,39 @@

router = APIRouter(prefix="/api/v1", tags=["ingestion_status"])

from enum import Enum


class IngestionState(str, Enum):
DONE = "DONE"
NOT_STARTED = "NOT_STARTED"


@router.get(
"/courses/{course_id}/lectures/{lecture_id}/lectureUnits/{lecture_unit_id}/ingestion-state",
dependencies=[Depends(TokenValidator())],
)
def get_lecture_unit_ingestion_state(
course_id: int, lecture_id: int, lecture_unit_id: int, base_url: str
course_id: int, lecture_id: int, lecture_unit_id: int, base_url: str = Query(...)
):
"""
:param course_id:
:param lecture_id:
:param lecture_unit_id:
:param base_url:
:return:
"""
db = VectorDatabase()
decoded_base_url = unquote(base_url)
result = db.lectures.query.fetch_objects(
filters=(
Filter.by_property(LectureSchema.BASE_URL.value).equal(decoded_base_url)
& Filter.by_property(LectureSchema.COURSE_ID.value).equal(course_id)
& Filter.by_property(LectureSchema.LECTURE_ID.value).equal(lecture_id)
& Filter.by_property(LectureSchema.LECTURE_UNIT_ID.value).equal(
lecture_unit_id
)
Filter.by_property(LectureSchema.BASE_URL.value).equal(decoded_base_url)
& Filter.by_property(LectureSchema.COURSE_ID.value).equal(course_id)
& Filter.by_property(LectureSchema.LECTURE_ID.value).equal(lecture_id)
& Filter.by_property(LectureSchema.LECTURE_UNIT_ID.value).equal(
lecture_unit_id
)
),
limit=1,
return_properties=[LectureSchema.LECTURE_UNIT_NAME.value],
Expand All @@ -35,12 +52,12 @@ def get_lecture_unit_ingestion_state(
if len(result.objects) > 0:
return Response(
status_code=status.HTTP_200_OK,
content='"DONE"',
content=json.dumps({"state": IngestionState.DONE.value}),
media_type="application/json",
)
else:
return Response(
status_code=status.HTTP_200_OK,
content='"NOT_STARTED"',
content=json.dumps({"state": IngestionState.NOT_STARTED.value}),
media_type="application/json",
)
2 changes: 1 addition & 1 deletion app/web/routers/webhooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def run_lecture_deletion_pipeline_worker(dto: LecturesDeletionExecutionDto):
db = VectorDatabase()
client = db.get_client()
pipeline = LectureIngestionPipeline(client=client, dto=None, callback=callback)
pipeline.delete_old_lectures(dto.lecture_units)
pipeline.delete_old_lectures(dto.lecture_units, dto.settings.artemis_base_url)
except Exception as e:
logger.error(f"Error while deleting lectures: {e}")
logger.error(traceback.format_exc())
Expand Down

0 comments on commit 481ce45

Please sign in to comment.