Skip to content

Open-source manufacturing ERP, MES and QMS. Quoting, MRP, inventory, shop floor, quality and lot/serial traceability on one Postgres schema, with a REST API and MCP server. Self-host or use Carbon Cloud.

build: update healthchecks

Brad Barbin1b2114fa67fe
diff --git a/apps/erp/app/routes/_public+/health.tsx b/apps/erp/app/routes/_public+/health.tsx
index 66971aee0d..2bd9ba1284 100644
--- a/apps/erp/app/routes/_public+/health.tsx
+++ b/apps/erp/app/routes/_public+/health.tsx
@@ -1,14 +1,49 @@
import { getCarbonServiceRole } from "@carbon/auth";
+// Simple health check that doesn't depend on database
export async function loader() {
try {
+ // Basic application health check
+ const startTime = Date.now();
+
+ // Optional: Add a lightweight database check with timeout
const client = getCarbonServiceRole();
- const test = await client.from("attributeDataType").select("*");
- if (test.error !== null) throw test.error;
- return new Response("OK");
+ const timeoutPromise = new Promise((_, reject) =>
+ setTimeout(() => reject(new Error("Health check timeout")), 5000)
+ );
+
+ const healthCheck = client
+ .from("attributeDataType")
+ .select("id")
+ .limit(1)
+ .single();
+
+ await Promise.race([healthCheck, timeoutPromise]);
+
+ const responseTime = Date.now() - startTime;
+
+ return new Response(
+ JSON.stringify({
+ status: "OK",
+ timestamp: new Date().toISOString(),
+ responseTime: `${responseTime}ms`,
+ }),
+ {
+ headers: { "Content-Type": "application/json" },
+ }
+ );
} catch (error: unknown) {
- // eslint-disable-next-line no-console
console.log("health ❌", { error });
- return new Response("ERROR", { status: 500 });
+ return new Response(
+ JSON.stringify({
+ status: "ERROR",
+ error: error instanceof Error ? error.message : "Unknown error",
+ timestamp: new Date().toISOString(),
+ }),
+ {
+ status: 500,
+ headers: { "Content-Type": "application/json" },
+ }
+ );
}
}
diff --git a/apps/mes/app/routes/_public+/health.tsx b/apps/mes/app/routes/_public+/health.tsx
index 66971aee0d..2bd9ba1284 100644
--- a/apps/mes/app/routes/_public+/health.tsx
+++ b/apps/mes/app/routes/_public+/health.tsx
@@ -1,14 +1,49 @@
import { getCarbonServiceRole } from "@carbon/auth";
+// Simple health check that doesn't depend on database
export async function loader() {
try {
+ // Basic application health check
+ const startTime = Date.now();
+
+ // Optional: Add a lightweight database check with timeout
const client = getCarbonServiceRole();
- const test = await client.from("attributeDataType").select("*");
- if (test.error !== null) throw test.error;
- return new Response("OK");
+ const timeoutPromise = new Promise((_, reject) =>
+ setTimeout(() => reject(new Error("Health check timeout")), 5000)
+ );
+
+ const healthCheck = client
+ .from("attributeDataType")
+ .select("id")
+ .limit(1)
+ .single();
+
+ await Promise.race([healthCheck, timeoutPromise]);
+
+ const responseTime = Date.now() - startTime;
+
+ return new Response(
+ JSON.stringify({
+ status: "OK",
+ timestamp: new Date().toISOString(),
+ responseTime: `${responseTime}ms`,
+ }),
+ {
+ headers: { "Content-Type": "application/json" },
+ }
+ );
} catch (error: unknown) {
- // eslint-disable-next-line no-console
console.log("health ❌", { error });
- return new Response("ERROR", { status: 500 });
+ return new Response(
+ JSON.stringify({
+ status: "ERROR",
+ error: error instanceof Error ? error.message : "Unknown error",
+ timestamp: new Date().toISOString(),
+ }),
+ {
+ status: 500,
+ headers: { "Content-Type": "application/json" },
+ }
+ );
}
}
diff --git a/sst.config.ts b/sst.config.ts
index 155ce85f6b..40c2d6ac11 100644
--- a/sst.config.ts
+++ b/sst.config.ts
@@ -28,6 +28,12 @@ export default $config({
{ listen: "443/https", forward: "3000/http" },
],
},
+ scaling: {
+ min: 1,
+ max: 10,
+ cpuUtilization: 70,
+ memoryUtilization: 80,
+ },
environment: {
AUTODESK_BUCKET_NAME: process.env.AUTODESK_BUCKET_NAME,
AUTODESK_CLIENT_ID: process.env.AUTODESK_CLIENT_ID,
@@ -85,6 +91,12 @@ export default $config({
{ listen: "443/https", forward: "3000/http" },
],
},
+ scaling: {
+ min: 1,
+ max: 10,
+ cpuUtilization: 70,
+ memoryUtilization: 80,
+ },
environment: {
AUTODESK_BUCKET_NAME: process.env.AUTODESK_BUCKET_NAME,
AUTODESK_CLIENT_ID: process.env.AUTODESK_CLIENT_ID,
@@ -124,7 +136,7 @@ export default $config({
name: "RateLimitRule",
statement: {
rateBasedStatement: {
- limit: 200,
+ limit: 1000,
aggregateKeyType: "IP",
},
},