Skip to content

Commit

Permalink
Make Ingestion Status updated through api calls
Browse files Browse the repository at this point in the history
  • Loading branch information
yassinsws committed Sep 5, 2024
1 parent 201b4b4 commit 2a11f63
Show file tree
Hide file tree
Showing 3 changed files with 116 additions and 0 deletions.
40 changes: 40 additions & 0 deletions app/web/routers/ingestion_status.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
from urllib.parse import unquote

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

from app.dependencies import TokenValidator
from ...vector_database.database import VectorDatabase
from ...vector_database.lecture_schema import LectureSchema

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


@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, baseUrl: str):
db = VectorDatabase()
decoded_base_url = unquote(baseUrl)
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)
),
limit=1,
return_properties=[LectureSchema.LECTURE_UNIT_NAME.value],
)

if len(result.objects) > 0:
return Response(
status_code=status.HTTP_200_OK,
content='"DONE"',
media_type="application/json"
)
else:
return Response(
status_code=status.HTTP_200_OK,
content='"NOT_STARTED"',
media_type="application/json"
)
45 changes: 45 additions & 0 deletions app/web/status/ingestion_status_callback.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
from typing import List

from .status_update import StatusCallback
from ...domain.ingestion.ingestion_status_update_dto import IngestionStatusUpdateDTO
from ...domain.status.stage_state_dto import StageStateEnum
from ...domain.status.stage_dto import StageDTO
import logging

logger = logging.getLogger(__name__)


class IngestionStatusCallback(StatusCallback):
"""
Callback class for updating the status of a Lecture ingestion Pipeline run.
"""

def __init__(
self,
run_id: str,
base_url: str,
initial_stages: List[StageDTO] = None,
lecture_unit_id: int = None,
):
url = f"{base_url}/api/public/pyris/webhooks/ingestion/runs/{run_id}/status"

current_stage_index = len(initial_stages) if initial_stages else 0
stages = initial_stages or []
stages += [
StageDTO(
weight=10, state=StageStateEnum.NOT_STARTED, name="Old slides removal"
),
StageDTO(
weight=60,
state=StageStateEnum.NOT_STARTED,
name="Slides Interpretation",
),
StageDTO(
weight=30,
state=StageStateEnum.NOT_STARTED,
name="Slides ingestion",
),
]
status = IngestionStatusUpdateDTO(stages=stages, id=lecture_unit_id)
stage = stages[current_stage_index]
super().__init__(url, run_id, status, stage, current_stage_index)
31 changes: 31 additions & 0 deletions app/web/status/lecture_deletion_status_callback.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
from typing import List

from .status_update import StatusCallback
from ...domain.ingestion.ingestion_status_update_dto import IngestionStatusUpdateDTO
from ...domain.status.stage_state_dto import StageStateEnum
from ...domain.status.stage_dto import StageDTO
import logging

logger = logging.getLogger(__name__)


class LecturesDeletionStatusCallback(StatusCallback):
"""
Callback class for updating the status of a Tutor Chat pipeline run.
"""

def __init__(
self, run_id: str, base_url: str, initial_stages: List[StageDTO] = None
):
url = f"{base_url}/api/public/pyris/webhooks/ingestion/runs/{run_id}/status"

current_stage_index = len(initial_stages) if initial_stages else 0
stages = initial_stages or []
stages += [
StageDTO(
weight=100, state=StageStateEnum.NOT_STARTED, name="Slides removal"
),
]
status = IngestionStatusUpdateDTO(stages=stages)
stage = stages[current_stage_index]
super().__init__(url, run_id, status, stage, current_stage_index)

0 comments on commit 2a11f63

Please sign in to comment.