Skip to content

Commit 5c1350f

Browse files
committed
add docker compose for job and add a readme to run the jobs framework and run the jobs
1 parent d7f01c0 commit 5c1350f

File tree

2 files changed

+189
-4
lines changed

2 files changed

+189
-4
lines changed

DEVELOPMENT_JOBS.md

Lines changed: 187 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,187 @@
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+
```

docker-compose.jobs.yml

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@ services:
66
# The image entrypoint already runs the LaunchQL CLI (`lql`).
77
# We only need to provide the subcommand and flags here.
88
entrypoint: ["lql", "server", "--port", "3000", "--origin", "*", "--strictAuth", "false"]
9-
depends_on:
10-
- postgres
119
environment:
1210
NODE_ENV: development
1311
# Server
@@ -21,7 +19,7 @@ services:
2119
PGPORT: "5432"
2220
PGUSER: postgres
2321
PGPASSWORD: password
24-
PGDATABASE: launchql # ensure this DB exists and has migrations applied
22+
PGDATABASE: launchql
2523
# API meta configuration (static mode for dev)
2624
API_ENABLE_META: "true"
2725
API_EXPOSED_SCHEMAS: "collections_public,meta_public"
@@ -69,7 +67,7 @@ services:
6967
PGHOST: postgres
7068
PGPASSWORD: password
7169
PGPORT: "5432"
72-
PGDATABASE: jobs # ensure this DB exists and has launchql-ext-jobs installed
70+
PGDATABASE: launchql
7371
JOBS_SCHEMA: app_jobs
7472

7573
# Worker configuration

0 commit comments

Comments
 (0)