@@ -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+ )
0 commit comments