Skip to content

Commit 6a8ba91

Browse files
committed
Refactor admin status, update DB config & scripts
1 parent fe74e7e commit 6a8ba91

4 files changed

Lines changed: 80 additions & 59 deletions

File tree

apps/api/src/routes/admin-status.ts

Lines changed: 61 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -19,56 +19,73 @@ const WORKER_NAMES = [
1919
'vm-teardown',
2020
]
2121

22-
export const AdminStatusRouter = HttpRouter.empty.pipe(
23-
HttpRouter.get(
24-
'/v1/admin/status',
25-
Effect.gen(function* () {
26-
const redis = yield* RedisService
27-
const nodeRepo = yield* NodeRepo
28-
const shutdown = yield* ShutdownController
22+
const handler = Effect.gen(function* () {
23+
const redis = yield* RedisService
24+
const nodeRepo = yield* NodeRepo
25+
const shutdown = yield* ShutdownController
2926

30-
// Redis health
31-
const redisOk = yield* redis.ping()
27+
// Redis health
28+
const redisOk = yield* redis.ping()
3229

33-
// Worker leader info
34-
const workers = yield* redis.getWorkerLeaderInfo(WORKER_NAMES)
30+
// Worker leader info
31+
const workers = yield* redis.getWorkerLeaderInfo(WORKER_NAMES)
3532

36-
// Nodes with heartbeat status
37-
const nodeRows = yield* nodeRepo.list()
38-
const nodes = yield* Effect.all(
39-
nodeRows.map((node) =>
40-
Effect.gen(function* () {
41-
const nodeIdStr = bytesToId(NODE_PREFIX, node.id)
42-
const heartbeatActive = yield* redis.hasNodeHeartbeat(nodeIdStr)
43-
return {
44-
id: nodeIdStr,
45-
status: node.status,
46-
heartbeat_active: heartbeatActive,
47-
}
48-
}),
49-
),
50-
)
33+
// Nodes with heartbeat status
34+
const nodeRows = yield* nodeRepo.list()
35+
const nodes = yield* Effect.all(
36+
nodeRows.map((node) =>
37+
Effect.gen(function* () {
38+
const nodeIdStr = bytesToId(NODE_PREFIX, node.id)
39+
const heartbeatActive = yield* redis.hasNodeHeartbeat(nodeIdStr)
40+
return {
41+
id: nodeIdStr,
42+
status: node.status,
43+
heartbeat_active: heartbeatActive,
44+
}
45+
}),
46+
),
47+
)
5148

52-
// Drain state
53-
const draining = yield* shutdown.isDraining
49+
// Drain state
50+
const draining = yield* shutdown.isDraining
5451

55-
return HttpServerResponse.unsafeJson({
56-
api: {
57-
status: 'ok',
58-
uptime_seconds: Math.floor(process.uptime()),
59-
version: '0.0.1',
60-
draining,
61-
},
62-
redis: {
63-
status: redisOk ? 'ok' : 'fail',
52+
return HttpServerResponse.unsafeJson({
53+
api: {
54+
status: 'ok',
55+
uptime_seconds: Math.floor(process.uptime()),
56+
version: '0.0.1',
57+
draining,
58+
},
59+
redis: {
60+
status: redisOk ? 'ok' : 'fail',
61+
},
62+
workers: workers.map((w) => ({
63+
name: w.name,
64+
active: w.active,
65+
ttl_ms: w.ttlMs,
66+
})),
67+
nodes,
68+
})
69+
}).pipe(
70+
Effect.catchAllDefect((defect) =>
71+
Effect.gen(function* () {
72+
const message = defect instanceof Error ? defect.message : String(defect)
73+
const stack = defect instanceof Error ? defect.stack : undefined
74+
yield* Effect.logError(`Admin status defect: ${message}`, stack ? { stack } : {})
75+
return HttpServerResponse.unsafeJson(
76+
{
77+
api: { status: 'error', uptime_seconds: Math.floor(process.uptime()), version: '0.0.1', draining: false },
78+
redis: { status: 'unknown' },
79+
workers: [],
80+
nodes: [],
81+
error: message,
6482
},
65-
workers: workers.map((w) => ({
66-
name: w.name,
67-
active: w.active,
68-
ttl_ms: w.ttlMs,
69-
})),
70-
nodes,
71-
})
83+
{ status: 500 },
84+
)
7285
}),
7386
),
7487
)
88+
89+
export const AdminStatusRouter = HttpRouter.empty.pipe(
90+
HttpRouter.get('/v1/admin/status', handler),
91+
)

packages/db/drizzle.config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { defineConfig } from 'drizzle-kit'
55
config({ path: resolve(process.cwd(), '../../.env') })
66

77
export default defineConfig({
8-
schema: './src/schema/index.ts',
8+
schema: './src/schema/*.ts',
99
out: './drizzle',
1010
dialect: 'mysql',
1111
dbCredentials: {

packages/db/package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,13 @@
1515
"typecheck": "tsc --noEmit",
1616
"lint": "echo 'no lint configured yet'",
1717
"test": "bun test",
18-
"db:generate": "tsx ./node_modules/.bin/drizzle-kit generate",
19-
"db:push": "tsx ./node_modules/.bin/drizzle-kit push",
20-
"db:migrate": "tsx ./node_modules/.bin/drizzle-kit migrate",
18+
"db:generate": "bunx drizzle-kit generate",
19+
"db:push": "bunx drizzle-kit push",
20+
"db:migrate": "bunx drizzle-kit migrate",
2121
"db:migrate:run": "bun run src/migrate.ts",
2222
"db:seed": "bun run src/seed.ts",
2323
"db:seed:dev": "bun run src/seed.ts --dev",
24-
"db:studio": "tsx ./node_modules/.bin/drizzle-kit studio"
24+
"db:studio": "bunx drizzle-kit studio"
2525
},
2626
"dependencies": {
2727
"drizzle-orm": "^0.39.0",

patches/drizzle-kit@0.31.9.patch

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
1-
diff --git a/bin.cjs b/bin.cjs
2-
index 327fdfde1aac8ddf7a0db6dc357796757be8986a..f4908ec68633aa2f5388db46197fa466f1d9cbf4 100755
31
--- a/bin.cjs
42
+++ b/bin.cjs
5-
@@ -18404,6 +18404,7 @@ AND
6-
const constraintValue = checkConstraintRow["CHECK_CLAUSE"];
7-
const tableName = checkConstraintRow["TABLE_NAME"];
8-
const tableInResult = result[tableName];
9-
+ if (!tableInResult) continue;
10-
tableInResult.checkConstraint[constraintName] = {
11-
name: constraintName,
12-
value: constraintValue
3+
@@ -16797,6 +16797,13 @@
4+
Module._resolveFilename = function(request, _parent) {
5+
const isCoreModule = _module2.builtinModules.includes(request);
6+
if (!isCoreModule) {
7+
+ if (request.endsWith('.js')) {
8+
+ const tsRequest = request.replace(/\.js$/, '.ts');
9+
+ try {
10+
+ const modifiedArguments2 = [tsRequest, ...[].slice.call(arguments, 1)];
11+
+ return originalResolveFilename.apply(this, modifiedArguments2);
12+
+ } catch (e) {}
13+
+ }
14+
const found = matchPath(request);
15+
if (found) {
16+
const modifiedArguments = [found, ...[].slice.call(arguments, 1)];

0 commit comments

Comments
 (0)