start coroutine from the thread instead of the wrapper normal func

This commit is contained in:
Viktor Barzin 2025-06-21 13:48:28 +00:00
parent 064f2651d5
commit 4e4a5ece15
No known key found for this signature in database
GPG key ID: 4056458DBDBF8863
2 changed files with 3 additions and 6 deletions

View file

@ -1,3 +1,4 @@
import asyncio
from pathlib import Path
import queue
from threading import Thread
@ -18,7 +19,7 @@ from ui_exporter import export_immoweb
app = FastAPI()
# Start worker thread
Thread(target=dump_listings_worker, daemon=True).start()
Thread(target=asyncio.run, args=[dump_listings_worker()], daemon=True).start()
# Allow CORS (for React frontend)
app.add_middleware(

View file

@ -16,10 +16,6 @@ task_queue = Queue(maxsize=1) # Disallow multiple in flight requests for now
task_results = {}
def dump_listings_worker() -> None:
return asyncio.run(_dump_listings_worker())
class TaskStatus(enum.StrEnum):
QUEUED = "queued"
PROCESSING = "processing"
@ -27,7 +23,7 @@ class TaskStatus(enum.StrEnum):
FAILED = "failed"
async def _dump_listings_worker() -> None: # global results is updated
async def dump_listings_worker() -> None: # global results is updated
"""Background worker that processes tasks"""
repository = ListingRepository(engine)
data_dir_path = Path("data/rs")