# Open Valstorm Worker (`apps/open-worker`) **High-Throughput Go Worker & WebSocket Hub for Open Valstorm** Built with **Go 1.23+** and **`pgx/v5`**, `open-worker` handles high-concurrency real-time WebSocket client subscriptions and asynchronous background event processing. --- ## 1. Responsibilities 1. **WebSocket Hub (`/ws`)**: - Manages persistent bi-directional connections to UI clients. - Pushes live record mutations (`record_created`, `record_updated`, `record_deleted`) directly to browser and desktop interfaces. 2. **Background Task Queue**: - Consumes asynchronous task queues for webhooks, email triggers, and scheduled jobs without blocking the main FastAPI event loop. 3. **Native PostgreSQL Access (`pgx/v5`)**: - Connects directly to `valstorm_directory` and individual tenant databases via high-performance connection pooling. --- ## 2. Quickstart Guide ### Run Locally ```bash cd apps/open-worker go run main.go ``` * **HTTP / Health Port:** `http://localhost:8080/health` * **WebSocket Endpoint:** `ws://localhost:8080/ws` ### Run in Docker ```bash docker compose -f docker-compose.open.yaml up -d open-worker ``` --- ## 3. Environment Variables | Variable | Default Value | Description | | :--- | :--- | :--- | | `PORT` | `8080` | Worker HTTP and WebSocket listen port | | `DIRECTORY_DB_URL` | `postgresql://valstorm:valstorm_password@localhost:5432/valstorm_directory` | PostgreSQL directory database connection string | | `REDIS_URL` | `redis://localhost:6379/0` | Valkey/Redis cache & pub/sub connection string | --- ## Direct Go HTTP & WebSocket Endpoints (`:8080`) Unlike Python routes on `open-api (:8010)`, performance-critical ingress endpoints are served directly by `open-worker (:8080)`: - **WebSocket Hub:** `GET /v1/ws/{org_id}/{user_id}`, `GET /v1/ws/create`, `POST /v1/ws/send_message`, `POST /v1/ws/desktop/execute` - **Fleet App Deployment:** `POST /v1/deployment/rollout`, `GET /v1/deployment/status/{job_id}`, `POST /v1/deployment/install` - **Sub-10ms AI Desktop Sync:** `POST /v1/ai/chat/{chat_id}/desktop-sync` - **High-Speed Public Form & Webhook Ingestion:** `POST /v1/inbound/submit`, `POST /v1/inbound/webhook` - **Public Calendar Booking Engine:** `GET /v1/booking/{slug}/availability`, `POST /v1/booking/{slug}/reserve` - **Telephony & Email Provider Webhooks:** `POST /v1/webhooks/telnyx/{org_id}`, `POST /v1/webhooks/twilio/{org_id}`, `POST /v1/email-services/sendgrid/webhook/{org_id}` - **OpenAPI & Route Introspection:** `GET /v1/openapi.json`, `GET /v1/routes`