Skip to content

Commit

Permalink
task is marked as completed after processing is done
Browse files Browse the repository at this point in the history
  • Loading branch information
nrjadkry committed Oct 15, 2024
1 parent ac122b4 commit 67acc32
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 6 deletions.
20 changes: 19 additions & 1 deletion src/backend/app/projects/image_processing.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,12 @@ def process_images_from_s3(self, bucket_name, name=None, options=[], webhook=Non


def download_and_upload_assets_from_odm_to_s3(
node_odm_url: str, task_id: str, dtm_project_id: uuid.UUID, dtm_task_id: uuid.UUID
db: Connection,
node_odm_url: str,
task_id: str,
dtm_project_id: uuid.UUID,
dtm_task_id: uuid.UUID,
user_id: str,
):
"""
Downloads results from ODM and uploads them to S3 (Minio).
Expand Down Expand Up @@ -225,6 +230,19 @@ def download_and_upload_assets_from_odm_to_s3(

log.info(f"Assets for task {task_id} successfully uploaded to S3.")

# Update background task status to COMPLETED
update_task_status_sync = async_to_sync(task_logic.update_task_state)
update_task_status_sync(
db,
dtm_project_id,
dtm_task_id,
user_id,
"Task completed.",
State.IMAGE_UPLOADED,
State.IMAGE_PROCESSED,
timestamp(),
)

except Exception as e:
log.error(f"Error downloading or uploading assets for task {task_id}: {e}")

Expand Down
5 changes: 1 addition & 4 deletions src/backend/app/projects/project_logic.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,10 +179,7 @@ def process_drone_images(
{"name": "orthophoto-resolution", "value": 5},
]

webhook_url = (
f"{settings.BACKEND_URL}/api/projects/odm/webhook/{project_id}/{task_id}/"
)

webhook_url = f"{settings.BACKEND_URL}/api/projects/odm/webhook/{user_id}/{project_id}/{task_id}/"
processor.process_images_from_s3(
settings.S3_BUCKET_NAME,
name=f"DTM-Task-{task_id}",
Expand Down
6 changes: 5 additions & 1 deletion src/backend/app/projects/project_routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -425,13 +425,15 @@ async def get_assets_info(


@router.post(
"/odm/webhook/{dtm_project_id}/{dtm_task_id}/",
"/odm/webhook/{dtm_user_id}/{dtm_project_id}/{dtm_task_id}/",
tags=["Image Processing"],
)
async def odm_webhook(
request: Request,
db: Annotated[Connection, Depends(database.get_db)],
dtm_project_id: uuid.UUID,
dtm_task_id: uuid.UUID,
dtm_user_id: str,
background_tasks: BackgroundTasks,
):
"""
Expand All @@ -458,10 +460,12 @@ async def odm_webhook(
# Call function to download assets from ODM and upload to S3
background_tasks.add_task(
image_processing.download_and_upload_assets_from_odm_to_s3,
db,
settings.NODE_ODM_URL,
task_id,
dtm_project_id,
dtm_task_id,
dtm_user_id,
)
elif status["code"] == 30:
# failed task
Expand Down

0 comments on commit 67acc32

Please sign in to comment.