@@ -10,13 +10,17 @@ import {
1010 handleSubscriptionEvent ,
1111} from "../mgmt/mod.ts" ;
1212import {
13+ enqueueMsg ,
1314 FensakConfigSource ,
1415 getComputedFensakConfig ,
1516 getSubscription ,
17+ MessageType ,
1618 mustGetGitHubOrgWithSubscription ,
19+ waitForHealthCheckResult ,
1720} from "../svcdata/mod.ts" ;
1821import type { GitHubOrgWithSubscription } from "../svcdata/mod.ts" ;
1922import { isOrgManager } from "../ghstd/mod.ts" ;
23+ import { getRandomString } from "../xtd/mod.ts" ;
2024
2125interface APIOrganization {
2226 slug : string ;
@@ -38,6 +42,8 @@ export function attachMgmtAPIRoutes(router: Router): void {
3842 const corsMW = oakCors ( { origin : corsOrigins } ) ;
3943
4044 router
45+ . get ( "/healthz" , healthCheck )
46+ . get ( "/sentry-test" , testSentry )
4147 . post (
4248 "/hooks/mgmt" ,
4349 middlewares . assertMgmtEvent ,
@@ -59,6 +65,35 @@ export function attachMgmtAPIRoutes(router: Router): void {
5965 ) ;
6066}
6167
68+ async function healthCheck ( ctx : Context ) : Promise < void > {
69+ const requestID = getRandomString ( 6 ) ;
70+ await enqueueMsg ( {
71+ type : MessageType . HealthCheck ,
72+ payload : {
73+ requestID : requestID ,
74+ } ,
75+ } ) ;
76+ const result = await waitForHealthCheckResult ( requestID ) ;
77+ if ( ! result ) {
78+ ctx . response . status = Status . InternalServerError ;
79+ ctx . response . body = {
80+ status : Status . InternalServerError ,
81+ msg : "timed out waiting for worker health result" ,
82+ } ;
83+ return ;
84+ }
85+
86+ ctx . response . status = Status . OK ;
87+ ctx . response . body = {
88+ status : Status . OK ,
89+ msg : "system ok" ,
90+ } ;
91+ }
92+
93+ function testSentry ( _ctx : Context ) : void {
94+ throw new Error ( "Test error to ensure sentry is working" ) ;
95+ }
96+
6297async function handleGetOrganizations ( ctx : Context ) : Promise < void > {
6398 const token = ctx . state . apiToken ;
6499 const octokit = new Octokit ( { auth : token } ) ;
0 commit comments