Skip to content

Commit

Permalink
Merge pull request #313 from hotosm/hotfix/task-status
Browse files Browse the repository at this point in the history
[hotfix]: update task status as completed after image processing...
  • Loading branch information
Pradip-p authored Oct 26, 2024
2 parents 4a07fe5 + 81391d9 commit dd14e85
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 20 deletions.
26 changes: 14 additions & 12 deletions src/backend/app/projects/image_processing.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from psycopg import Connection
from asgiref.sync import async_to_sync
from app.config import settings
from app.db import database


class DroneImageProcessor:
Expand Down Expand Up @@ -193,7 +194,6 @@ def process_images_from_s3(self, bucket_name, name=None, options=[], webhook=Non


async def download_and_upload_assets_from_odm_to_s3(
db: Connection,
node_odm_url: str,
task_id: str,
dtm_project_id: uuid.UUID,
Expand All @@ -212,7 +212,6 @@ async def download_and_upload_assets_from_odm_to_s3(
"""
log.info(f"Starting download for task {task_id}")

# Replace with actual ODM node details and URL
node = Node.from_url(node_odm_url)

Expand All @@ -236,16 +235,19 @@ async 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
await task_logic.update_task_state(
db,
dtm_project_id,
dtm_task_id,
user_id,
comment,
current_state,
State.IMAGE_PROCESSED,
timestamp(),
)
pool = await database.get_db_connection_pool()

async with pool.connection() as conn:
await task_logic.update_task_state(
db=conn,
project_id=dtm_project_id,
task_id=dtm_task_id,
user_id=user_id,
comment="Task completed.",
initial_state=State.IMAGE_UPLOADED,
final_state=State.IMAGE_PROCESSED,
updated_at=timestamp(),
)

except Exception as e:
log.error(f"Error downloading or uploading assets for task {task_id}: {e}")
Expand Down
13 changes: 5 additions & 8 deletions src/backend/app/projects/project_routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -483,14 +483,11 @@ 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,
State.IMAGE_UPLOADED,
"Task completed.",
node_odm_url=settings.NODE_ODM_URL,
task_id=task_id,
dtm_project_id=dtm_project_id,
dtm_task_id=dtm_task_id,
user_id=dtm_user_id,
)
elif status["code"] == 30:
current_state = await task_logic.get_current_state(
Expand Down

0 comments on commit dd14e85

Please sign in to comment.