44 lines
1.3 KiB
Python
44 lines
1.3 KiB
Python
|
||
#!/usr/bin/env python3
|
||
"""examples/demo_run_cluster_export.py
|
||
|
||
Launch ClusterExportWorker via FlowArtifact wrapper, mirroring the embedder demo.
|
||
"""
|
||
|
||
from __future__ import annotations
|
||
import asyncio
|
||
import logging
|
||
from pathlib import Path
|
||
import os
|
||
|
||
from librarian_vspace.vquery.cluster_export_worker import ClusterExportWorker, ClusterExportInput
|
||
from librarian_core.workers.base import FlowArtifact
|
||
|
||
COURSE_ID = 15512 # example id
|
||
|
||
logger = logging.getLogger(__name__)
|
||
|
||
def _load_env(path: Path) -> None:
|
||
if not path.is_file():
|
||
return
|
||
for line in path.read_text().splitlines():
|
||
if line.strip() and not line.startswith("#") and "=" in line:
|
||
k, v = [p.strip() for p in line.split("=", 1)]
|
||
os.environ.setdefault(k, v)
|
||
|
||
async def _main() -> None:
|
||
payload = ClusterExportInput(course_id=COURSE_ID)
|
||
|
||
worker = ClusterExportWorker()
|
||
art = FlowArtifact.new(run_id="", dir=Path.cwd(), data=payload)
|
||
result_artifact = await worker.flow()(art) # FlowArtifact
|
||
|
||
output = result_artifact.data # ClusterExportOutput
|
||
logger.info("✅ Worker finished – output directory: %s", output.output_dir)
|
||
|
||
if __name__ == "__main__":
|
||
logging.basicConfig(level=logging.INFO, format="[%(levelname)s] %(message)s")
|
||
APP_DIR = Path(__file__).resolve().parent
|
||
_load_env(APP_DIR / ".env")
|
||
asyncio.run(_main())
|