import asyncio
import sys
import os
from dotenv import load_dotenv

load_dotenv()

# Add the current directory to sys.path
sys.path.append(os.path.dirname(os.path.abspath(__file__)))

from app.database import Base, engine
from app.ingest import run_worker

# Ensure tables exist
Base.metadata.create_all(bind=engine)

if __name__ == "__main__":
    print("Starting Background Worker...")
    try:
        asyncio.run(run_worker())
    except KeyboardInterrupt:
        print("Worker stopped.")
