Files
microservice/api/api_v2/modules/tasks/tasks.py

20 lines
461 B
Python

from celery import Celery
from celery_app import celery_app
import asyncio
import logging
from typing import Dict, Any
from contextlib import asynccontextmanager
def run_async_task(async_func, *args, **kwargs):
"""Helper function to run async functions in Celery tasks"""
loop = asyncio.new_event_loop()
asyncio.set_event_loop(loop)
try:
return loop.run_until_complete(async_func(*args, **kwargs))
finally:
loop.close()