-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjustfile
More file actions
374 lines (288 loc) · 12.9 KB
/
justfile
File metadata and controls
374 lines (288 loc) · 12.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
# Kronos — Distributed Job Scheduling and Execution Engine
set dotenv-load
# Default: list all recipes
default:
@just --list
# ─── Environment ──────────────────────────────────────────────
export TE_DATABASE_URL := env("TE_DATABASE_URL", "postgresql://kronos:kronos@localhost:5432/taskexecutor")
export TE_API_KEY := env("TE_API_KEY", "dev-api-key")
export TE_ENCRYPTION_KEY := env("TE_ENCRYPTION_KEY", "0000000000000000000000000000000000000000000000000000000000000000")
# ─── Setup ────────────────────────────────────────────────────
# One-time project setup: start DB, run migrations, build SDK, install CLI deps
setup: db-up db-migrate build-sdk cli-install
@echo "Setup complete. Run 'just dev' to start all services."
# Create .env from example if it doesn't exist
init-env:
@[ -f .env ] || cp .env.example .env && echo ".env ready"
# ─── Database ─────────────────────────────────────────────────
# Start PostgreSQL
db-up:
docker compose up -d postgres
@echo "Waiting for PostgreSQL to be ready..."
@sleep 3
# Stop PostgreSQL
db-down:
docker compose down
# Run SQL migrations
db-migrate:
PGPASSWORD=kronos psql -h localhost -U kronos -d taskexecutor < migrations/20260317000000_initial.sql
PGPASSWORD=kronos psql -h localhost -U kronos -d taskexecutor < migrations/20260318000000_multi_tenancy.sql
PGPASSWORD=kronos psql -h localhost -U kronos -d taskexecutor < migrations/20260322000000_txn_based_pickup.sql
PGPASSWORD=kronos psql -h localhost -U kronos -d taskexecutor < migrations/20260322000001_pg_cron.sql
# Reset database (drop + recreate + migrate)
db-reset:
sqlx database drop --database-url "$TE_DATABASE_URL" -y || true
sqlx database create --database-url "$TE_DATABASE_URL"
just db-migrate
# Open a SQL shell
db-shell:
PGPASSWORD=kronos psql -h localhost -U kronos -d taskexecutor
# ─── Build ────────────────────────────────────────────────────
# Build all Rust crates
build:
cargo build --workspace
# Build in release mode
build-release:
cargo build --workspace --release
# Check all crates compile
check:
cargo check --workspace
# ─── Smithy + SDK ─────────────────────────────────────────────
export SMITHY_MAVEN_REPOS := "https://repo.maven.apache.org/maven2|https://sandbox.assets.juspay.in/smithy/m2"
# Validate Smithy models. Run before regeneration to surface model errors
# with clean messages instead of cryptic codegen failures.
smithy-validate:
cd smithy && smithy validate
# Full regeneration: validate models, run smithy-build, then sync the
# committed Rust SDK at sdks/rust/. Edit smithy/model/* → run this →
# commit the resulting diff (model + sdks/rust/) in the same PR.
smithy-build: smithy-validate
cd smithy && smithy build
rm -rf crates/client
cp -R smithy/build/smithy/source/rust-client-codegen crates/client
# Restore the tracked README.md (DO NOT EDIT warning) that the wipe removed
git checkout -- crates/client/README.md
@echo "Regenerated crates/client. Review with: git diff -- crates/client"
# Build the generated TypeScript SDK (npm install + compile)
build-sdk: smithy-build
cd smithy/build/smithy/source/typescript-client-codegen && npm install && npm run build
# Install CLI dependencies (links to built SDK)
cli-install: build-sdk
cd cli && npm install
# Regenerate SDK and reinstall CLI (after Smithy model changes)
sdk-refresh: build-sdk cli-install
# ─── Run Services ─────────────────────────────────────────────
# Run the API server (port 8080)
api:
cargo run -p kronos-api
# Run the worker
worker:
cargo run -p kronos-worker
# Run the scheduler (cron materializer, delayed promoter, stuck reclaimer)
scheduler:
cargo run -p kronos-scheduler
# Run the mock HTTP server (port 9999)
mock-server:
cargo run -p kronos-mock-server
# Run all services in parallel (API + worker + scheduler + mock-server)
dev:
#!/usr/bin/env bash
set -e
trap 'kill 0' EXIT
echo "Starting all Kronos services..."
echo " API: http://localhost:8080 (metrics at /metrics)"
echo " Worker: metrics on :9090"
echo " Scheduler: metrics on :9091"
echo " Mock: http://localhost:9999"
cargo run -p kronos-api &
TE_METRICS_PORT=9090 cargo run -p kronos-worker &
cargo run -p kronos-mock-server &
echo "All services starting. Press Ctrl+C to stop all."
wait
# ─── Test ─────────────────────────────────────────────────────
# Run HTTP dispatcher tests (requires mock-server running)
test-http:
cargo test -p kronos-worker --lib dispatcher::http::tests
# Run Kafka dispatcher tests (requires: docker compose --profile kafka up -d)
test-kafka:
cargo test -p kronos-worker --features kafka --lib dispatcher::kafka::tests -- --test-threads=1
# Run Redis stream dispatcher tests (requires: docker compose --profile redis up -d)
test-redis:
cargo test -p kronos-worker --features redis-stream --lib dispatcher::redis_stream::tests -- --test-threads=1
# Run all dispatcher tests (requires kafka, redis, and mock-server)
test-dispatchers: test-http test-kafka test-redis
# Load test: create N jobs of each type (IMMEDIATE, DELAYED, CRON) and track completion
# Usage: just load-test 50
load-test N="10":
cd cli && npx tsx src/load-test.ts {{N}}
# Load test (fire-and-forget, no polling)
load-test-nw N="10":
cd cli && npx tsx src/load-test.ts {{N}} --no-wait
# Run the immediate execution end-to-end test
test-immediate:
cd cli && npx tsx src/test-immediate.ts
# Run the delayed execution end-to-end test (requires scheduler running)
test-delayed:
cd cli && npx tsx src/test-delayed.ts
# Run the CRON job end-to-end test (requires scheduler running)
test-cron:
cd cli && npx tsx src/test-cron.ts
# Full integration test: setup → dev services → run test
test-e2e: build
#!/usr/bin/env bash
set -e
trap 'kill 0' EXIT
echo "Starting services for e2e test..."
cargo run -p kronos-api &
API_PID=$!
cargo run -p kronos-worker &
WORKER_PID=$!
cargo run -p kronos-scheduler &
SCHEDULER_PID=$!
cargo run -p kronos-mock-server &
MOCK_PID=$!
# Wait for services to be ready
echo "Waiting for services to start..."
for i in $(seq 1 30); do
if curl -sf http://localhost:8080/health > /dev/null 2>&1 && \
curl -sf http://localhost:9999/health > /dev/null 2>&1; then
echo "Services ready."
break
fi
if [ "$i" -eq 30 ]; then
echo "ERROR: Services failed to start within 30s"
exit 1
fi
sleep 1
done
cd cli && npx tsx src/test-immediate.ts && npx tsx src/test-delayed.ts && npx tsx src/test-cron.ts
EXIT_CODE=$?
echo "Shutting down services..."
exit $EXIT_CODE
# Run the Haskell SDK example (requires db-up, db-migrate)
test-haskell: build
#!/usr/bin/env bash
set -e
trap 'kill 0' EXIT
echo "Starting services for Haskell e2e test..."
cargo run -p kronos-api &
cargo run -p kronos-worker &
cargo run -p kronos-mock-server &
echo "Waiting for services to start..."
for i in $(seq 1 30); do
if curl -sf http://localhost:8080/health > /dev/null 2>&1 && \
curl -sf http://localhost:9999/health > /dev/null 2>&1; then
echo "Services ready."
break
fi
if [ "$i" -eq 30 ]; then
echo "ERROR: Services failed to start within 30s"
exit 1
fi
sleep 1
done
echo "Building and running Haskell example..."
cd haskell-example && nix-shell \
-p "haskell.packages.ghc96.ghcWithPackages (p: with p; [aeson text network-uri http-client http-types bytestring mtl time containers http-date case-insensitive])" \
cabal-install \
--run "cabal run kronos-example 2>&1"
EXIT_CODE=$?
echo "Shutting down services..."
exit $EXIT_CODE
# ─── KMS (LocalStack) ────────────────────────────────────────
# Start LocalStack for KMS dev testing
kms-up:
docker compose --profile kms up -d localstack
@echo "Waiting for LocalStack to be ready..."
@sleep 3
@echo "LocalStack KMS ready at http://localhost:4566"
# Stop LocalStack
kms-down:
docker compose --profile kms down
# Create a KMS key on LocalStack + encrypt DB URL → .env.kms
kms-init: kms-up
unset TE_DATABASE_URL TE_API_KEY TE_ENCRYPTION_KEY && ./scripts/kms-init.sh
# Encrypt a plaintext value with the LocalStack KMS key
kms-encrypt VALUE:
@./scripts/kms-encrypt.sh "{{VALUE}}"
# Run API + worker with KMS feature enabled (uses .env.kms)
kms-dev:
#!/usr/bin/env bash
set -e
if [ ! -f .env.kms ]; then
echo "Error: .env.kms not found. Run 'just kms-init' first." >&2
exit 1
fi
# cp .env.kms .env
trap 'kill 0' EXIT
echo "Starting KMS-enabled dev services..."
cargo run --features kms -p kronos-api &
TE_METRICS_PORT=9090 RUST_LOG=info cargo run --features kms -p kronos-worker &
cargo run -p kronos-mock-server &
echo "All services starting with KMS. Press Ctrl+C to stop."
wait
# ─── Docker Prod ─────────────────────────────────────────────
# Start full prod-like Docker environment (postgres + KMS + all services)
docker-prod-up:
./scripts/docker-prod.sh
# Stop and clean up prod-like Docker environment
docker-prod-down:
./scripts/docker-prod-down.sh
# ─── Cargo utilities ─────────────────────────────────────────
# Run clippy lints
lint:
cargo clippy --workspace -- -D warnings
# Format code
fmt:
cargo fmt --all
# Format check (CI)
fmt-check:
cargo fmt --all -- --check
# ─── Docker ──────────────────────────────────────────────────
# Start all infrastructure (DB + Kafka + Redis)
infra-up:
docker compose --profile kafka --profile redis up -d
# Stop all infrastructure
infra-down:
docker compose --profile kafka --profile redis down
# ─── Monitoring ─────────────────────────────────────────────
# Start Prometheus + Grafana (Grafana at http://localhost:3001, admin/kronos)
monitoring-up:
docker compose --profile monitoring up -d
@echo "Prometheus: http://localhost:9099"
@echo "Grafana: http://localhost:3001 (admin / kronos)"
# Stop monitoring stack
monitoring-down:
docker compose --profile monitoring down
# Start everything: infra + monitoring
all-up:
docker compose --profile kafka --profile redis --profile monitoring up -d
@echo "All infrastructure started."
@echo "Prometheus: http://localhost:9099"
@echo "Grafana: http://localhost:3001 (admin / kronos)"
# Stop everything
all-down:
docker compose --profile kafka --profile redis --profile monitoring down
# ─── Dashboard ──────────────────────────────────────────────
# Build the dashboard WASM hydration bundle (requires wasm-pack and wasm32 target)
dashboard-build:
cd crates/dashboard && wasm-pack build --target web --release -- --features hydrate
cd crates/dashboard && tailwindcss -i input.css -o pkg/tailwind-output.css --minify
# Build dashboard in dev mode (faster, no optimizations)
dashboard-build-dev:
cd crates/dashboard && wasm-pack build --target web --dev -- --features hydrate
cd crates/dashboard && tailwindcss -i input.css -o pkg/tailwind-output.css
# Run the dashboard via the API server (SSR mode)
dashboard:
TE_MODE=both TE_DASHBOARD_DIST_DIR=crates/dashboard/pkg cargo run -p kronos-api
# Install dashboard build tools
dashboard-setup:
rustup target add wasm32-unknown-unknown
cargo install wasm-pack
# ─── Cleanup ─────────────────────────────────────────────────
# Clean all build artifacts
clean:
cargo clean
rm -rf smithy/build
rm -rf cli/node_modules cli/dist
rm -rf crates/dashboard/pkg