Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: added asyncio event loop to call async update_task_state #274

Merged
merged 2 commits into from
Oct 9, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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