Skip to content

Commit

Permalink
Health check
Browse files Browse the repository at this point in the history
  • Loading branch information
pontusab committed Jul 13, 2024
1 parent 7d94f4d commit ff66693
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 12 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/preview-engine.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@ jobs:
packageManager: bun
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
workingDirectory: "apps/engine"
wranglerVersion: "3.63.2"
wranglerVersion: "3.64.0"
command: deploy --minify src/index.ts --name=engine-staging
2 changes: 1 addition & 1 deletion .github/workflows/production-engine.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@ jobs:
packageManager: bun
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
workingDirectory: "apps/engine"
wranglerVersion: "3.63.2"
wranglerVersion: "3.64.0"
command: deploy --minify src/index.ts --name=engine
6 changes: 3 additions & 3 deletions apps/engine/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@
"@hono/swagger-ui": "^0.4.0",
"@hono/zod-openapi": "^0.14.9",
"@hono/zod-validator": "^0.2.2",
"hono": "^4.4.12",
"hono": "^4.4.13",
"typesense": "^1.8.2",
"xior": "^0.5.3",
"zod": "^3.23.8"
},
"devDependencies": {
"@cloudflare/workers-types": "^4.20240620.0",
"@cloudflare/workers-types": "^4.20240712.0",
"@types/bun": "^1.1.6",
"wrangler": "^3.63.2"
"wrangler": "^3.64.0"
}
}
10 changes: 3 additions & 7 deletions apps/engine/src/routes/health/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { Bindings } from "@/common/bindings";
import { ErrorSchema } from "@/common/schema";
import { Provider } from "@/providers";
import { SearchClient } from "@/utils/search";
import { getHealthCheck } from "@/utils/search";
import { createRoute } from "@hono/zod-openapi";
import { OpenAPIHono } from "@hono/zod-openapi";
import { env } from "hono/adapter";
Expand Down Expand Up @@ -44,15 +44,11 @@ app.openapi(indexRoute, async (c) => {
envs,
});

const typesense = SearchClient(envs);
const searchResponse = await typesense.health.retrieve();
const search = await getHealthCheck(envs);

const allServices = {
...providers,
search: {
healthy:
typeof searchResponse === "string" && JSON.parse(searchResponse).ok,
},
search,
};

const isHealthy = Object.values(allServices).every(
Expand Down
10 changes: 10 additions & 0 deletions apps/engine/src/utils/search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,13 @@ export function SearchClient(envs: Bindings) {
connectionTimeoutSeconds: 2,
});
}

export async function getHealthCheck(envs: Bindings) {
const typesense = SearchClient(envs);
const searchResponse = await typesense.health.retrieve();

return {
healthy:
typeof searchResponse === "string" && JSON.parse(searchResponse).ok,
};
}

0 comments on commit ff66693

Please sign in to comment.