# `apps/worker-nest` — Queue worker host

Consumes the BullMQ queues produced by every API host:

| Queue           | Processor               | What it does                                                |
| --------------- | ----------------------- | ----------------------------------------------------------- |
| `audit-events`  | `AuditProcessor`        | Persist to Postgres `audit_logs` via Prisma                 |
| `notifications` | `NotificationProcessor` | Route by `kind` → SmtpChannel / FcmChannel / NoopSmsChannel |

## Run

```bash
cp .env.example .env             # set DATABASE_URL + REDIS_URL at minimum
docker compose up -d              # Postgres + Redis
pnpm --filter @loma-portal/worker-nest dev
```

## Why a separate process?

- Audit + notifications must not block the request path. The API hosts only enqueue.
- The worker can scale horizontally and independently. K8s scales it per queue depth (Phase 8 ships the HPA manifest).
- A worker crash never takes down the request path.

## Channel registration

`NotificationProcessor` builds channels at startup based on env vars:

- `SMTP_HOST` + `SMTP_FROM` → email channel enabled
- `FCM_PROJECT_ID` + `FCM_CLIENT_EMAIL` + `FCM_PRIVATE_KEY` → push channel enabled
- `sms` → always `NoopSmsChannel` until a provider is chosen
