Skip to content

Supercharge your AI agents with data from the web and beyond. Building the library for superintelligence. 🔥

Update Kubernetes configs for playwright-service, api, and worker

Jakob Stadlhuberbe9e7f9edf03
diff --git a/apps/api/src/controllers/liveness.ts b/apps/api/src/controllers/liveness.ts
new file mode 100644
index 000000000..8ff1a96f9
--- /dev/null
+++ b/apps/api/src/controllers/liveness.ts
@@ -0,0 +1,6 @@
+import { Request, Response } from "express";
+
+export async function livenessController(req: Request, res: Response) {
+ //TODO: add checks if the application is live and healthy like checking the redis connection
+ res.status(200).json({ status: "ok" });
+}
diff --git a/apps/api/src/controllers/readiness.ts b/apps/api/src/controllers/readiness.ts
new file mode 100644
index 000000000..cdb1f02c3
--- /dev/null
+++ b/apps/api/src/controllers/readiness.ts
@@ -0,0 +1,6 @@
+import { Request, Response } from "express";
+
+export async function readinessController(req: Request, res: Response) {
+ // TODO: add checks when the application is ready to serve traffic
+ res.status(200).json({ status: "ok" });
+}
diff --git a/apps/api/src/routes/v0.ts b/apps/api/src/routes/v0.ts
index a9a3a9bfc..4284b77c6 100644
--- a/apps/api/src/routes/v0.ts
+++ b/apps/api/src/routes/v0.ts
@@ -7,6 +7,8 @@ import { crawlJobStatusPreviewController } from "../../src/controllers/status";
import { searchController } from "../../src/controllers/search";
import { crawlCancelController } from "../../src/controllers/crawl-cancel";
import { keyAuthController } from "../../src/controllers/keyAuth";
+import {livenessController} from "../controllers/liveness";
+import {readinessController} from "../controllers/readiness";
export const v0Router = express.Router();
@@ -23,3 +25,6 @@ v0Router.get("/v0/keyAuth", keyAuthController);
// Search routes
v0Router.post("/v0/search", searchController);
+// Health/Probe routes
+v0Router.get("/v0/health/liveness", livenessController);
+v0Router.get("/v0/health/readiness", readinessController);
diff --git a/apps/playwright-service/main.py b/apps/playwright-service/main.py
index bd6b14e3f..c9099d3b0 100644
--- a/apps/playwright-service/main.py
+++ b/apps/playwright-service/main.py
@@ -5,7 +5,7 @@ the HTML content of a specified URL. It supports optional proxy settings and med
from os import environ
-from fastapi import FastAPI
+from fastapi import FastAPI, Response
from fastapi.responses import JSONResponse
from playwright.async_api import Browser, async_playwright
from pydantic import BaseModel
@@ -39,14 +39,28 @@ async def shutdown_event():
"""Event handler for application shutdown to close the browser."""
await browser.close()
[email protected]("/health/liveness")
+def liveness_probe():
+ """Endpoint for liveness probe."""
+ return JSONResponse(content={"status": "ok"}, status_code=200)
+
+
[email protected]("/health/readiness")
+async def readiness_probe():
+ """Endpoint for readiness probe. Checks if the browser instance is ready."""
+ if browser:
+ return JSONResponse(content={"status": "ok"}, status_code=200)
+ return JSONResponse(content={"status": "Service Unavailable"}, status_code=503)
+
+
@app.post("/html")
async def root(body: UrlModel):
"""
Endpoint to fetch and return HTML content of a given URL.
-
+
Args:
body (UrlModel): The URL model containing the target URL, wait time, and timeout.
-
+
Returns:
JSONResponse: The HTML content of the page.
"""