start coroutine from the thread instead of the wrapper normal func
This commit is contained in:
parent
064f2651d5
commit
4e4a5ece15
2 changed files with 3 additions and 6 deletions
|
|
@ -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(
|
||||
|
|
|
|||
|
|
@ -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")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue