Skip to content

Commit

Permalink
feat: service health endpoint & docker health check
Browse files Browse the repository at this point in the history
  • Loading branch information
tada5hi committed Feb 19, 2024
1 parent 463b03a commit aa4ef27
Show file tree
Hide file tree
Showing 6 changed files with 72 additions and 0 deletions.
3 changes: 3 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,8 @@ RUN chmod +x ./entrypoint.sh

EXPOSE 3000

HEALTHCHECK --interval=10s --timeout=5s --retries=5 \
CMD wget --proxy off --no-verbose --tries=1 --spider http://localhost:3000/ || exit 1

ENTRYPOINT ["/bin/sh", "./entrypoint.sh"]
CMD ["cli", "start"]
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './module';
17 changes: 17 additions & 0 deletions packages/server-core/src/http/controllers/core/root/module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import {
DController, DGet, DRequest, DResponse, DTags,
} from '@routup/decorators';
import type { EndpointInfo } from './status';
import { useStatusRouteHandler } from './status';

@DTags('root')
@DController('')
export class RootController {
@DGet('/', [])
async status(
@DRequest() req: any,
@DResponse() res: any,
): Promise<EndpointInfo> {
return useStatusRouteHandler(req, res);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/*
* Copyright (c) 2023.
* Author Peter Placzek (tada5hi)
* For the full copyright and license information,
* view the LICENSE file that was distributed with this source code.
*/

export * from './module';
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* Copyright (c) 2023.
* Author Peter Placzek (tada5hi)
* For the full copyright and license information,
* view the LICENSE file that was distributed with this source code.
*/

import path from 'node:path';
import { load } from 'locter';
import process from 'node:process';
import { send } from 'routup';
import type { Request, Response } from 'routup';

export type EndpointInfo = {
version: string,
timestamp: number,
};

let info : undefined | EndpointInfo;

export async function useInfo() {
if (typeof info !== 'undefined') {
return info;
}

const pkgJson = await load(path.join(process.cwd(), 'package.json'));

info = {
version: pkgJson.version,
timestamp: Date.now(),
};

return info;
}
export async function useStatusRouteHandler(req: Request, res: Response) : Promise<any> {
const status = await useInfo();
status.timestamp = Date.now();

return send(res, status);
}
3 changes: 3 additions & 0 deletions packages/server-core/src/http/routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import { ProposalStationController } from './controllers/core/project-node';
import { NodeController } from './controllers/core/node';
import { AnalysisController } from './controllers/core/analysis';
import { AnalysisNodeController } from './controllers/core/analysis-node';
import { RootController } from './controllers/core/root';
import { ServiceController } from './controllers/special/service';
import { MasterImageGroupController } from './controllers/core/master-image-group';
import { RegistryController } from './controllers/core/registry';
Expand All @@ -44,6 +45,8 @@ export function registerControllers(router: Router) {
TrainLogController,
AnalysisNodeController,

RootController,

// Extra
ServiceController,
],
Expand Down

0 comments on commit aa4ef27

Please sign in to comment.