Skip to content

Commit

Permalink
Merge pull request #274 from hotosm/feat/update-completed-task
Browse files Browse the repository at this point in the history
fix: added asyncio event loop to call async update_task_state
  • Loading branch information
Pradip-p authored Oct 9, 2024
2 parents 31c52fe + f361b6c commit a26a517
Showing 1 changed file with 15 additions and 10 deletions.
25 changes: 15 additions & 10 deletions src/backend/app/projects/image_processing.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from loguru import logger as log
from concurrent.futures import ThreadPoolExecutor
from psycopg import Connection
import asyncio


class DroneImageProcessor:
Expand Down Expand Up @@ -125,7 +126,7 @@ def download_results(self, task, output_path):
log.info("Download completed.")
return path

async def process_images_from_s3(self, bucket_name, name=None, options=[]):
def process_images_from_s3(self, bucket_name, name=None, options=[]):
"""
Processes images from MinIO storage.
Expand Down Expand Up @@ -156,15 +157,19 @@ async 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.
await task_logic.update_task_state(
self.db,
self.project_id,
self.task_id,
self.user_id,
"Task completed.",
State.IMAGE_UPLOADED,
State.IMAGE_PROCESSED,
timestamp(),
# Call the async function using asyncio
loop = asyncio.get_event_loop()
loop.run_until_complete(
task_logic.update_task_state(
self.db,
self.project_id,
self.task_id,
self.user_id,
"Task completed.",
State.IMAGE_UPLOADED,
State.IMAGE_PROCESSED,
timestamp(),
)
)
return task

Expand Down

0 comments on commit a26a517

Please sign in to comment.