diff options
| author | Acid Chicken <root@acid-chicken.com> | 2024-05-23 15:19:52 +0900 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-05-23 15:19:52 +0900 |
| commit | 611e303bab1ace64c7ab1611e35d850a96f0bace (patch) | |
| tree | 7dbde5302219db6cbc1786e234ea361f9a4c2446 /packages/backend/src/server/HealthServerService.ts | |
| parent | feat(frontend): 長いテキストをペーストした際にテキストフ... (diff) | |
| download | sharkey-611e303bab1ace64c7ab1611e35d850a96f0bace.tar.gz sharkey-611e303bab1ace64c7ab1611e35d850a96f0bace.tar.bz2 sharkey-611e303bab1ace64c7ab1611e35d850a96f0bace.zip | |
feat(backend): add /healthz endpoint (#13834)
* feat(backend): add /healthz endpoint
* feat(backend): also check meilisearch status if available
* style: header
* chore: no-store
* chore: healthcheck.sh
* style: format
Diffstat (limited to 'packages/backend/src/server/HealthServerService.ts')
| -rw-r--r-- | packages/backend/src/server/HealthServerService.ts | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/packages/backend/src/server/HealthServerService.ts b/packages/backend/src/server/HealthServerService.ts new file mode 100644 index 0000000000..2c3ed85925 --- /dev/null +++ b/packages/backend/src/server/HealthServerService.ts @@ -0,0 +1,54 @@ +/* + * SPDX-FileCopyrightText: syuilo and misskey-project + * SPDX-License-Identifier: AGPL-3.0-only + */ + +import { Inject, Injectable } from '@nestjs/common'; +import * as Redis from 'ioredis'; +import { DataSource } from 'typeorm'; +import { bindThis } from '@/decorators.js'; +import { DI } from '@/di-symbols.js'; +import { readyRef } from '@/boot/ready.js'; +import type { FastifyInstance, FastifyPluginOptions } from 'fastify'; +import type { MeiliSearch } from 'meilisearch'; + +@Injectable() +export class HealthServerService { + constructor( + @Inject(DI.redis) + private redis: Redis.Redis, + + @Inject(DI.redisForPub) + private redisForPub: Redis.Redis, + + @Inject(DI.redisForSub) + private redisForSub: Redis.Redis, + + @Inject(DI.redisForTimelines) + private redisForTimelines: Redis.Redis, + + @Inject(DI.db) + private db: DataSource, + + @Inject(DI.meilisearch) + private meilisearch: MeiliSearch | null, + ) {} + + @bindThis + public createServer(fastify: FastifyInstance, options: FastifyPluginOptions, done: (err?: Error) => void) { + fastify.get('/', async (request, reply) => { + reply.code(await Promise.all([ + new Promise<void>((resolve, reject) => readyRef.value ? resolve() : reject()), + this.redis.ping(), + this.redisForPub.ping(), + this.redisForSub.ping(), + this.redisForTimelines.ping(), + this.db.query('SELECT 1'), + ...(this.meilisearch ? [this.meilisearch.health()] : []), + ]).then(() => 200, () => 503)); + reply.header('Cache-Control', 'no-store'); + }); + + done(); + } +} |