Skip to content

Commit

Permalink
changing the order of things, now s3 runs synchronous and elastic asy…
Browse files Browse the repository at this point in the history
…nchronous
  • Loading branch information
Jackson Barbosa committed Dec 28, 2023
1 parent 37ca9d7 commit e46a9a3
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 19 deletions.
16 changes: 9 additions & 7 deletions nexus/task_managers/file_manager/celery_file_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,23 @@ def __init__(self, file_database: FileDataBase):
self._file_database = file_database

def upload_file(self, file: bytes, content_base_uuid: str, extension_file: str, user_email: str):
file_database_response = self._file_database.add_file(file)
if file_database_response.status != 0:
return {
"task_status": ContentBaseFileTaskManager.STATUS_FAIL,
"error": file_database_response.err
}
content_base_file_dto = ContentBaseFileDTO(
file=file,
user_email=user_email,
content_base_uuid=content_base_uuid,
extension_file=extension_file,
file_url=""
file_url=file_database_response.file_url
)

destination_path = os.path.join(settings.STATIC_ROOT, file.name)
with open(destination_path, 'wb') as destination_file:
destination_file.write(file.read())
content_base_file = CreateContentBaseFileUseCase().create_content_base_file(content_base_file=content_base_file_dto)
task_manager = CeleryTaskManagerUseCase().create_celery_task_manager(content_base_file=content_base_file)
print(f"[ FILEMANAGER] task_manager: {task_manager.uuid} - destination_path: {destination_path}")
add_file.apply_async(args=[str(task_manager.uuid), destination_path])
print(f"[ FILEMANAGER] task_manager: {task_manager.uuid}")
add_file.apply_async(args=[str(task_manager.uuid)])
response = {
"task_uuid": task_manager.uuid,
"task_status": task_manager.status,
Expand Down
13 changes: 1 addition & 12 deletions nexus/task_managers/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,14 @@
from nexus.task_managers.models import ContentBaseFileTaskManager

@app.task
def add_file(task_manager_uuid, file):
def add_file(task_manager_uuid):
try:
task_manager = CeleryTaskManagerUseCase().get_task_manager_by_uuid(task_uuid=task_manager_uuid)
task_manager.update_status(ContentBaseFileTaskManager.STATUS_LOADING)
print(f"[ ADD FILE ] - updated status from task {task_manager.uuid}")
except Exception as exception:
print(f"[ ADD FILE ] - error: {exception}")
return
file_database = s3FileDatabase()
response = file_database.add_file(file)
if response.status == 0:
task_manager.content_base_file.file_url = response.url
task_manager.content_base_file.save(update_fields=["file_url"])
task_manager.update_status(ContentBaseFileTaskManager.STATUS_PROCESSING)
print(f"[ ADD FILE TASK ] - success on add file to file database {task_manager.content_base_file.uuid}")
else:
task_manager.update_status(ContentBaseFileTaskManager.STATUS_FAIL)
print("[ ADD FILE TASK ] - fail on add file to file database")
return
sentenx_file_database = SentenXFileDataBase()
sentenx_response = sentenx_file_database.add_file(task_manager)
if sentenx_response.status_code == 200:
Expand Down

0 comments on commit e46a9a3

Please sign in to comment.