Skip to content

Commit

Permalink
Add: NexusRESTClient; call nexus endpoint after indexing document
Browse files Browse the repository at this point in the history
  • Loading branch information
AlisoSouza committed Dec 19, 2023
1 parent 2b56939 commit 36f064a
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
4 changes: 4 additions & 0 deletions app/celery.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from app.indexer.indexer_file_manager import IndexerFileManager
from app.downloaders.s3 import S3FileDownloader

from app.handlers.content_bases import NexusRESTClient

celery = Celery(__name__)
celery.conf.broker_url = os.environ.get(
Expand All @@ -24,4 +25,7 @@ def index_file_data(content_base: Dict) -> bool:
os.environ.get("AWS_STORAGE_SECRET_KEY")
)
manager = IndexerFileManager(file_downloader, main_app.content_base_indexer)
index_result: bool = manager.index_file(content_base)
NexusRESTClient().index_succedded(task_succeded=index_result, nexus_task_uuid=content_base.get("task_uuid"))

return manager.index_file(content_base)
22 changes: 22 additions & 0 deletions app/handlers/content_bases.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
from typing import Annotated
from app.handlers.authorizations import token_verification

import requests, os


class ContentBaseIndexRequest(BaseModel):
file: str
Expand Down Expand Up @@ -73,3 +75,23 @@ def search(self, request: ContentBaseSearchRequest, Authorization: Annotated[str
filter=request.filter
)
return ContentBaseSearchResponse(response=response)


class NexusRESTClient:
token = os.environ.get("NEXUS_AI_TOKEN")
base_url = os.environ.get("NEXUS_AI_URL")

def __init__(self) -> None:
self.headers = {
'Authorization': self.token,
'Content-Type': "application/json"
}

def index_succedded(self, task_succeded: bool, nexus_task_uuid: str) -> None:
endpoint = f'{self.base_url}/api/v1/content-base-file'
data = {
"status": int(task_succeded),
"task_uuid": nexus_task_uuid,
}
response = requests.patch(url=endpoint, data=data, headers=self.headers)
response.raise_for_status()

0 comments on commit 36f064a

Please sign in to comment.