"""Event publishing. GCP: publish a JSON message to Pub/Sub; an Argo Events sensor turns it into an Argo Workflow. Local: run Nextflow directly in a background task so `docker compose up` gives a working demo. """ import asyncio import json import uuid from app.config import settings async def publish_vcf_uploaded(job_id: uuid.UUID, vcf_uri: str) -> None: message = {"job_id": str(job_id), "vcf_uri": vcf_uri} if settings.pubsub_topic: from google.cloud import pubsub_v1 # optional dependency, installed in the GCP image publisher = pubsub_v1.PublisherClient() publisher.publish(settings.pubsub_topic, json.dumps(message).encode()) return cmd = [ "nextflow", "run", "/pipeline/main.nf", "-profile", "docker", "--vcf", vcf_uri, "--job_id", str(job_id), "--db_url", settings.database_url, ] try: await asyncio.create_subprocess_exec(*cmd) except FileNotFoundError: # Nextflow is not installed in this environment (no Java toolchain yet); # leave the job queued instead of crashing the request. print(f"[rarelens] nextflow not found; cannot start pipeline for job {job_id}", flush=True)