Skip to content

Commit

Permalink
feat: update task state to reflect the start of image processing
Browse files Browse the repository at this point in the history
  • Loading branch information
Pradip-p committed Oct 8, 2024
1 parent befca95 commit 475527e
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 5 deletions.
17 changes: 14 additions & 3 deletions src/backend/app/projects/image_processing.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ def download_results(self, task, output_path):
log.info("Download completed.")
return path

def process_images_from_s3(self, bucket_name, name=None, options=[]):
async def process_images_from_s3(self, bucket_name, name=None, options=[]):
"""
Processes images from MinIO storage.
Expand All @@ -136,13 +136,24 @@ def process_images_from_s3(self, bucket_name, name=None, options=[]):
:param options: Processing options ([{'name': optionName, 'value': optionValue}, ...]).
:return: The task object.
"""
# Create a temporary directory to store downloaded images
# Create a temporary directory to store downloaded imagesfeat/update-completed-task
temp_dir = tempfile.mkdtemp()
try:
self.download_images_from_s3(bucket_name, temp_dir)

images_list = self.list_images(temp_dir)

# TODO: Update task state to reflect completion of image uploads (will remove thsi.).
await task_logic.update_task_state(
self.db,
self.project.id,
self.task_id,
self.user_id,
"Task images processing started.",
State.LOCKED_FOR_MAPPING,
State.IMAGE_PROCESSED,
timestamp(),
)
# Start a new processing task
task = self.process_new_task(images_list, name=name, options=options)
# Monitor task progress
Expand All @@ -156,7 +167,7 @@ def process_images_from_s3(self, bucket_name, name=None, options=[]):
s3_path = f"projects/{self.project_id}/{self.task_id}/assets.zip"
add_file_to_bucket(bucket_name, path_to_download, s3_path)
# now update the task as completed in Db.
task_logic.update_task_state(
await task_logic.update_task_state(
self.db,
self.project_id,
self.task_id,
Expand Down
16 changes: 14 additions & 2 deletions src/backend/app/projects/project_routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import uuid
from typing import Annotated, Optional
from uuid import UUID
from app.tasks import task_logic
import geojson
from datetime import timedelta
from fastapi import (
Expand All @@ -24,13 +25,13 @@
from shapely.ops import unary_union
from app.projects import project_schemas, project_deps, project_logic
from app.db import database
from app.models.enums import HTTPStatus
from app.models.enums import HTTPStatus, State
from app.s3 import s3_client
from app.config import settings
from app.users.user_deps import login_required
from app.users.user_schemas import AuthUser
from app.tasks import task_schemas
from app.utils import geojson_to_kml
from app.utils import geojson_to_kml, timestamp
from app.users import user_schemas


Expand Down Expand Up @@ -352,6 +353,17 @@ async def process_imagery(
db: Annotated[Connection, Depends(database.get_db)],
):
user_id = user_data.id
# TODO: Update task state to reflect completion of image uploads.
await task_logic.update_task_state(
db,
project.id,
task_id,
user_id,
"Task images upload completed.",
State.LOCKED_FOR_MAPPING,
State.IMAGE_UPLOADED,
timestamp(),
)
background_tasks.add_task(
project_logic.process_drone_images, project.id, task_id, user_id, db
)
Expand Down

0 comments on commit 475527e

Please sign in to comment.