|
| 1 | +# Jobs Development Setup |
| 2 | + |
| 3 | +This guide covers a local development workflow for the jobs stack: |
| 4 | + |
| 5 | +- Postgres + `launchql-ext-jobs` |
| 6 | +- LaunchQL API server |
| 7 | +- `simple-email` function |
| 8 | +- `knative-job-service` |
| 9 | + |
| 10 | +It assumes: |
| 11 | + |
| 12 | +- You have Docker / Docker Compose v2 installed. |
| 13 | +- You are using `pgpm` (not `lql`) for database initialization. |
| 14 | +- You have the latest `pgpm` installed (`npm i -g pgpm` or equivalent). |
| 15 | + |
| 16 | +--- |
| 17 | + |
| 18 | +## 1. Start Postgres (and Minio) |
| 19 | + |
| 20 | +From the `constructive/` directory: |
| 21 | + |
| 22 | +```sh |
| 23 | +docker compose up -d postgres |
| 24 | +``` |
| 25 | + |
| 26 | +This uses `docker-compose.yml` and creates a Docker network called `constructive-net` that other services will join. |
| 27 | + |
| 28 | +--- |
| 29 | + |
| 30 | +## 2. Configure your local Postgres env (pgenv) |
| 31 | + |
| 32 | +Add this helper to your shell config (for example in `~/.zshrc`): |
| 33 | + |
| 34 | +```sh |
| 35 | +pgenv() { |
| 36 | + export PGHOST=localhost |
| 37 | + export PGPORT=5432 |
| 38 | + export PGUSER=postgres |
| 39 | + export PGPASSWORD=password |
| 40 | + export PGDATABASE=launchql |
| 41 | + echo "PostgreSQL environment variables set" |
| 42 | +} |
| 43 | +``` |
| 44 | + |
| 45 | +Then in a new shell (or after re-sourcing `~/.zshrc`), run: |
| 46 | + |
| 47 | +```sh |
| 48 | +pgenv |
| 49 | +``` |
| 50 | + |
| 51 | +This ensures all subsequent `pgpm` and `psql` commands point at the same local database. |
| 52 | + |
| 53 | +--- |
| 54 | + |
| 55 | +## 3. Bootstrap roles and database with pgpm |
| 56 | + |
| 57 | +Make sure `pgpm` is installed and up to date. |
| 58 | + |
| 59 | +From the `constructive/` directory (with `pgenv` applied): |
| 60 | + |
| 61 | +1. Bootstrap admin users: |
| 62 | + |
| 63 | + ```sh |
| 64 | + pgpm admin-users bootstrap --yes |
| 65 | + pgpm admin-users add --test --yes |
| 66 | + ``` |
| 67 | + |
| 68 | +2. Create the `launchql` database (if it does not already exist): |
| 69 | + |
| 70 | + ```sh |
| 71 | + createdb launchql |
| 72 | + ``` |
| 73 | + |
| 74 | +3. Deploy the main app and jobs packages into `launchql`: |
| 75 | + |
| 76 | + ```sh |
| 77 | + pgpm deploy --yes --database "$PGDATABASE" --package app-svc-local |
| 78 | + pgpm deploy --yes --database "$PGDATABASE" --package db-meta |
| 79 | + pgpm deploy --yes --database "$PGDATABASE" --package launchql-database-jobs |
| 80 | + ``` |
| 81 | + |
| 82 | +At this point, the app schema and `database-jobs` should be installed and `app_jobs.*` should be available in the `launchql` database. |
| 83 | + |
| 84 | +--- |
| 85 | + |
| 86 | +## 4. Start jobs stack (API + worker + function) |
| 87 | + |
| 88 | +With Postgres initialized, bring up the jobs-related services using `docker-compose.jobs.yml`: |
| 89 | + |
| 90 | +```sh |
| 91 | +docker compose -f docker-compose.jobs.yml up |
| 92 | +``` |
| 93 | + |
| 94 | +Or run detached: |
| 95 | + |
| 96 | +```sh |
| 97 | +docker compose -f docker-compose.jobs.yml up -d |
| 98 | +``` |
| 99 | + |
| 100 | +This starts: |
| 101 | + |
| 102 | +- `launchql-server` – GraphQL API server |
| 103 | +- `simple-email` – Knative-style HTTP function |
| 104 | +- `knative-job-service` – jobs runtime (callback server + worker + scheduler) |
| 105 | + |
| 106 | +By default, all three services use the published image: |
| 107 | + |
| 108 | +```text |
| 109 | +ghcr.io/constructive-io/launchql:b88e3d1 |
| 110 | +``` |
| 111 | + |
| 112 | +If you want to test a local build instead, build the image from the `constructive/` workspace and update `image:` in `docker-compose.jobs.yml` to point to your local tag, for example: |
| 113 | + |
| 114 | +```sh |
| 115 | +docker build -t constructive-local . |
| 116 | +``` |
| 117 | + |
| 118 | +Then in `docker-compose.jobs.yml`: |
| 119 | + |
| 120 | +```yaml |
| 121 | +image: constructive-local |
| 122 | +``` |
| 123 | +
|
| 124 | +All services are attached to the shared `constructive-net` network and talk to the `postgres` container by hostname `postgres`. |
| 125 | + |
| 126 | +--- |
| 127 | + |
| 128 | +## 5. Enqueue a test job (simple-email) |
| 129 | + |
| 130 | +With the jobs stack running, you can enqueue a test job from your host into the Postgres container: |
| 131 | + |
| 132 | +```sh |
| 133 | +docker exec -it postgres \ |
| 134 | + psql -U postgres -d launchql -c " |
| 135 | + SELECT app_jobs.add_job( |
| 136 | + '00000000-0000-0000-0000-000000000001'::uuid, |
| 137 | + 'simple-email', |
| 138 | + json_build_object( |
| 139 | + |
| 140 | + 'subject', 'Hello from LaunchQL jobs', |
| 141 | + 'html', '<p>Hi from simple-email (dry run)</p>' |
| 142 | + )::json |
| 143 | + ); |
| 144 | + " |
| 145 | +``` |
| 146 | + |
| 147 | +You should then see the job picked up by `knative-job-service` and the email payload logged by the `simple-email` container in `docker compose -f docker-compose.jobs.yml logs -f`. |
| 148 | + |
| 149 | +--- |
| 150 | + |
| 151 | +## 6. Inspect logs and iterate |
| 152 | + |
| 153 | +To watch logs while you develop: |
| 154 | + |
| 155 | +```sh |
| 156 | +docker compose -f docker-compose.jobs.yml logs -f |
| 157 | +``` |
| 158 | + |
| 159 | +Useful containers: |
| 160 | + |
| 161 | +- `launchql-server` |
| 162 | +- `simple-email` |
| 163 | +- `knative-job-service` |
| 164 | +- `postgres` (from `docker-compose.yml`) |
| 165 | + |
| 166 | +If you change Docker images, environment variables, or code inside the image, restart the stack: |
| 167 | + |
| 168 | +```sh |
| 169 | +docker compose -f docker-compose.jobs.yml down |
| 170 | +docker compose -f docker-compose.jobs.yml up --build |
| 171 | +``` |
| 172 | + |
| 173 | +--- |
| 174 | + |
| 175 | +## 7. Stopping services |
| 176 | + |
| 177 | +To stop only the jobs stack: |
| 178 | + |
| 179 | +```sh |
| 180 | +docker compose -f docker-compose.jobs.yml down |
| 181 | +``` |
| 182 | + |
| 183 | +To stop everything, including Postgres and Minio: |
| 184 | + |
| 185 | +```sh |
| 186 | +docker compose down |
| 187 | +``` |
0 commit comments